Commit | Line | Data |
---|---|---|
6fa3eb70 S |
1 | /***************************************************************************** |
2 | * | |
3 | * Filename: | |
4 | * --------- | |
5 | * battery_common.c | |
6 | * | |
7 | * Project: | |
8 | * -------- | |
9 | * Android_Software | |
10 | * | |
11 | * Description: | |
12 | * ------------ | |
13 | * This Module defines functions of mt6323 Battery charging algorithm | |
14 | * and the Anroid Battery service for updating the battery status | |
15 | * | |
16 | * Author: | |
17 | * ------- | |
18 | * Oscar Liu | |
19 | * | |
20 | ****************************************************************************/ | |
21 | #include <linux/init.h> /* For init/exit macros */ | |
22 | #include <linux/module.h> /* For MODULE_ marcros */ | |
23 | #include <linux/fs.h> | |
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> | |
30 | #include <linux/fs.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> | |
38 | #include <linux/fs.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> | |
50 | #ifdef CONFIG_OF | |
51 | #include <linux/of.h> | |
52 | #include <linux/of_irq.h> | |
53 | #include <linux/of_address.h> | |
54 | #endif | |
55 | #include <linux/suspend.h> | |
56 | ||
57 | #include <asm/scatterlist.h> | |
58 | #include <asm/uaccess.h> | |
59 | #include <asm/io.h> | |
60 | #include <asm/irq.h> | |
61 | #include <mach/hardware.h> | |
62 | #include <mach/system.h> | |
63 | #include <mach/mt_sleep.h> | |
64 | ||
65 | #include <mach/mt_typedefs.h> | |
66 | #include <mach/mt_gpt.h> | |
67 | #include <mach/mt_boot.h> | |
68 | ||
69 | #include <cust_charging.h> | |
70 | #include <mach/upmu_common.h> | |
71 | #include <mach/upmu_hw.h> | |
4b9e9796 | 72 | #include <mach/upmu_sw.h> |
6fa3eb70 S |
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" | |
80 | ||
81 | #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT) | |
82 | #include <mach/diso.h> | |
83 | #endif | |
84 | ||
85 | #if defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT) | |
86 | #include "cust_pe.h" | |
87 | #endif | |
88 | /* ////////////////////////////////////////////////////////////////////////////// */ | |
89 | /* Battery Logging Entry */ | |
90 | /* ////////////////////////////////////////////////////////////////////////////// */ | |
91 | int Enable_BATDRV_LOG = BAT_LOG_CRTI; | |
6fa3eb70 S |
92 | |
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; | |
99 | /* Debug Msg */ | |
100 | static char *DISO_state_s[8] = { | |
101 | "IDLE", | |
102 | "OTG_ONLY", | |
103 | "USB_ONLY", | |
104 | "USB_WITH_OTG", | |
105 | "DC_ONLY", | |
106 | "DC_WITH_OTG", | |
107 | "DC_WITH_USB", | |
108 | "DC_USB_OTG", | |
109 | }; | |
110 | #endif | |
111 | ||
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 */ | |
119 | ||
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 */ | |
126 | ||
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; | |
140 | ||
141 | #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT) | |
142 | kal_bool g_vcdt_irq_delay_flag = 0; | |
143 | #endif | |
144 | ||
145 | #if defined(MTK_TEMPERATURE_RECHARGE_SUPPORT) | |
146 | kal_uint32 g_batt_temp_status = TEMP_POS_NORMAL; | |
147 | #endif | |
148 | ||
149 | kal_bool battery_suspended = KAL_FALSE; | |
150 | #ifdef MTK_ENABLE_AGING_ALGORITHM | |
151 | extern U32 suspend_time; | |
152 | #endif | |
153 | ||
154 | #if defined(CUST_SYSTEM_OFF_VOLTAGE) | |
155 | #define SYSTEM_OFF_VOLTAGE CUST_SYSTEM_OFF_VOLTAGE | |
156 | #endif | |
157 | ||
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----------------------------------------- */ | |
173 | ||
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; | |
178 | ||
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 }; | |
186 | ||
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; | |
191 | #endif | |
192 | ||
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; | |
211 | ||
212 | /* ////////////////////////////////////////////////////////////////////////////// */ | |
213 | /* FOR ADB CMD */ | |
214 | /* ////////////////////////////////////////////////////////////////////////////// */ | |
215 | /* Dual battery */ | |
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; | |
223 | ||
224 | /* ////////////////////////////////////////////////////////////////////////////// */ | |
225 | /* FOR ANDROID BATTERY SERVICE */ | |
226 | /* ////////////////////////////////////////////////////////////////////////////// */ | |
227 | ||
228 | struct wireless_data { | |
229 | struct power_supply psy; | |
230 | int WIRELESS_ONLINE; | |
231 | }; | |
232 | ||
233 | struct ac_data { | |
234 | struct power_supply psy; | |
235 | int AC_ONLINE; | |
236 | }; | |
237 | ||
238 | struct usb_data { | |
239 | struct power_supply psy; | |
240 | int USB_ONLINE; | |
241 | }; | |
242 | ||
243 | struct battery_data { | |
244 | struct power_supply psy; | |
245 | int BAT_STATUS; | |
246 | int BAT_HEALTH; | |
247 | int BAT_PRESENT; | |
248 | int BAT_TECHNOLOGY; | |
249 | int BAT_CAPACITY; | |
250 | /* Add for Battery Service */ | |
251 | int BAT_batt_vol; | |
252 | int BAT_batt_temp; | |
253 | /* Add for EM */ | |
254 | int BAT_TemperatureR; | |
255 | int BAT_TempBattVoltage; | |
256 | int BAT_InstatVolt; | |
257 | int BAT_BatteryAverageCurrent; | |
258 | int BAT_BatterySenseVoltage; | |
259 | int BAT_ISenseVoltage; | |
260 | int BAT_ChargerVoltage; | |
261 | /* Dual battery */ | |
262 | int status_smb; | |
263 | int capacity_smb; | |
264 | int present_smb; | |
265 | int adjust_power; | |
266 | }; | |
267 | ||
268 | static enum power_supply_property wireless_props[] = { | |
269 | POWER_SUPPLY_PROP_ONLINE, | |
270 | }; | |
271 | ||
272 | static enum power_supply_property ac_props[] = { | |
273 | POWER_SUPPLY_PROP_ONLINE, | |
274 | }; | |
275 | ||
276 | static enum power_supply_property usb_props[] = { | |
277 | POWER_SUPPLY_PROP_ONLINE, | |
278 | }; | |
279 | ||
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, | |
289 | /* Add for EM */ | |
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, | |
297 | /* Dual battery */ | |
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, | |
303 | }; | |
304 | ||
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; | |
309 | #endif | |
310 | /* [PLATFORM]-Add-END by TCTSZ.leo.guo */ | |
311 | ||
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); | |
320 | #else | |
321 | #define mt_usb_connect() do { } while (0) | |
322 | #define mt_usb_disconnect() do { } while (0) | |
323 | #endif | |
324 | /* extern int set_rtc_spare_fg_value(int val); */ | |
325 | ||
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); | |
329 | #endif | |
330 | ||
331 | void check_battery_exist(void); | |
332 | void charging_suspend_enable(void) | |
333 | { | |
334 | U32 charging_enable = true; | |
335 | ||
336 | suspend_discharging = 0; | |
337 | battery_charging_control(CHARGING_CMD_ENABLE,&charging_enable); | |
338 | } | |
339 | ||
340 | void charging_suspend_disable(void) | |
341 | { | |
342 | U32 charging_enable = false; | |
343 | ||
344 | suspend_discharging = 1; | |
345 | battery_charging_control(CHARGING_CMD_ENABLE,&charging_enable); | |
346 | } | |
347 | ||
348 | int read_tbat_value(void) | |
349 | { | |
350 | return BMT_status.temperature; | |
351 | } | |
352 | ||
353 | int get_charger_detect_status(void) | |
354 | { | |
355 | kal_bool chr_status; | |
356 | ||
357 | battery_charging_control(CHARGING_CMD_GET_CHARGER_DET_STATUS, &chr_status); | |
358 | return chr_status; | |
359 | } | |
360 | ||
361 | #if defined(CONFIG_MTK_POWER_EXT_DETECT) | |
362 | kal_bool bat_is_ext_power(void) | |
363 | { | |
364 | kal_bool pwr_src = 0; | |
365 | ||
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); | |
368 | return pwr_src; | |
369 | } | |
370 | #endif | |
371 | /* ///////////////////////////////////////////////////////////////////////////////////////// */ | |
372 | /* // PMIC PCHR Related APIs */ | |
373 | /* ///////////////////////////////////////////////////////////////////////////////////////// */ | |
374 | kal_bool upmu_is_chr_det(void) | |
375 | { | |
376 | #if !defined(CONFIG_POWER_EXT) | |
377 | kal_uint32 tmp32; | |
378 | #endif | |
379 | ||
380 | if(battery_charging_control == NULL) | |
381 | { | |
382 | battery_charging_control = chr_control_interface; | |
383 | } | |
384 | #if defined(CONFIG_POWER_EXT) | |
385 | /* return KAL_TRUE; */ | |
386 | return get_charger_detect_status(); | |
387 | #else | |
388 | if (suspend_discharging==1) | |
389 | return KAL_FALSE; | |
390 | ||
391 | tmp32 = get_charger_detect_status(); | |
392 | ||
393 | #ifdef CONFIG_MTK_POWER_EXT_DETECT | |
394 | if (KAL_TRUE == bat_is_ext_power()) | |
395 | return tmp32; | |
396 | #endif | |
397 | ||
398 | if (tmp32 == 0) { | |
399 | return KAL_FALSE; | |
400 | } else { | |
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"); | |
405 | ||
406 | return KAL_TRUE; | |
407 | } else { | |
408 | battery_xlog_printk(BAT_LOG_CRTI, | |
409 | "[upmu_is_chr_det] Charger exist but USB is host\n"); | |
410 | ||
411 | return KAL_FALSE; | |
412 | } | |
413 | #else | |
414 | return KAL_TRUE; | |
415 | #endif | |
416 | } | |
417 | #endif | |
418 | } | |
419 | EXPORT_SYMBOL(upmu_is_chr_det); | |
420 | ||
421 | ||
422 | void wake_up_bat(void) | |
423 | { | |
424 | battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] wake_up_bat. \r\n"); | |
425 | ||
426 | chr_wake_up_bat = KAL_TRUE; | |
427 | bat_thread_timeout = KAL_TRUE; | |
428 | #ifdef MTK_ENABLE_AGING_ALGORITHM | |
429 | suspend_time = 0; | |
430 | #endif | |
431 | _g_bat_sleep_total_time = 0; | |
432 | wake_up(&bat_thread_wq); | |
433 | } | |
434 | EXPORT_SYMBOL(wake_up_bat); | |
435 | ||
436 | ||
437 | static ssize_t bat_log_write(struct file *filp, const char __user *buff, size_t len, loff_t *data) | |
438 | { | |
4b9e9796 S |
439 | char proc_bat_data; |
440 | ||
441 | if ((len <= 0) || copy_from_user(&proc_bat_data, buff, 1)) { | |
6fa3eb70 S |
442 | battery_xlog_printk(BAT_LOG_FULL, "bat_log_write error.\n"); |
443 | return -EFAULT; | |
444 | } | |
445 | ||
4b9e9796 | 446 | if (proc_bat_data == '1') { |
6fa3eb70 S |
447 | battery_xlog_printk(BAT_LOG_CRTI, "enable battery driver log system\n"); |
448 | Enable_BATDRV_LOG = 1; | |
4b9e9796 | 449 | } else if (proc_bat_data == '2') { |
6fa3eb70 S |
450 | battery_xlog_printk(BAT_LOG_CRTI, "enable battery driver log system:2\n"); |
451 | Enable_BATDRV_LOG = 2; | |
452 | } else { | |
453 | battery_xlog_printk(BAT_LOG_CRTI, "Disable battery driver log system\n"); | |
454 | Enable_BATDRV_LOG = 0; | |
455 | } | |
456 | ||
457 | return len; | |
458 | } | |
459 | ||
460 | static const struct file_operations bat_proc_fops = { | |
461 | .write = bat_log_write, | |
462 | }; | |
463 | ||
464 | int init_proc_log(void) | |
465 | { | |
466 | int ret = 0; | |
467 | ||
468 | #if 1 | |
469 | proc_create("batdrv_log", 0644, NULL, &bat_proc_fops); | |
470 | battery_xlog_printk(BAT_LOG_CRTI, "proc_create bat_proc_fops\n"); | |
471 | #else | |
472 | proc_entry = create_proc_entry("batdrv_log", 0644, NULL); | |
473 | ||
474 | if (proc_entry == NULL) { | |
475 | ret = -ENOMEM; | |
476 | battery_xlog_printk(BAT_LOG_FULL, "init_proc_log: Couldn't create proc entry\n"); | |
477 | } else { | |
478 | proc_entry->write_proc = bat_log_write; | |
479 | battery_xlog_printk(BAT_LOG_CRTI, "init_proc_log loaded.\n"); | |
480 | } | |
481 | #endif | |
482 | ||
483 | return ret; | |
484 | } | |
485 | ||
486 | ||
487 | static int wireless_get_property(struct power_supply *psy, | |
488 | enum power_supply_property psp, union power_supply_propval *val) | |
489 | { | |
490 | int ret = 0; | |
491 | struct wireless_data *data = container_of(psy, struct wireless_data, psy); | |
492 | ||
493 | switch (psp) { | |
494 | case POWER_SUPPLY_PROP_ONLINE: | |
495 | val->intval = data->WIRELESS_ONLINE; | |
496 | break; | |
497 | default: | |
498 | ret = -EINVAL; | |
499 | break; | |
500 | } | |
501 | return ret; | |
502 | } | |
503 | ||
504 | static int ac_get_property(struct power_supply *psy, | |
505 | enum power_supply_property psp, union power_supply_propval *val) | |
506 | { | |
507 | int ret = 0; | |
508 | struct ac_data *data = container_of(psy, struct ac_data, psy); | |
509 | ||
510 | switch (psp) { | |
511 | case POWER_SUPPLY_PROP_ONLINE: | |
512 | val->intval = data->AC_ONLINE; | |
513 | break; | |
514 | default: | |
515 | ret = -EINVAL; | |
516 | break; | |
517 | } | |
518 | return ret; | |
519 | } | |
520 | ||
521 | static int usb_get_property(struct power_supply *psy, | |
522 | enum power_supply_property psp, union power_supply_propval *val) | |
523 | { | |
524 | int ret = 0; | |
525 | struct usb_data *data = container_of(psy, struct usb_data, psy); | |
526 | ||
527 | switch (psp) { | |
528 | case POWER_SUPPLY_PROP_ONLINE: | |
529 | #if defined(CONFIG_POWER_EXT) | |
530 | /* #if 0 */ | |
531 | data->USB_ONLINE = 1; | |
532 | val->intval = data->USB_ONLINE; | |
533 | #else | |
534 | #if defined(CONFIG_MTK_POWER_EXT_DETECT) | |
535 | if (KAL_TRUE == bat_is_ext_power()) | |
536 | data->USB_ONLINE = 1; | |
537 | #endif | |
538 | val->intval = data->USB_ONLINE; | |
539 | #endif | |
540 | break; | |
541 | default: | |
542 | ret = -EINVAL; | |
543 | break; | |
544 | } | |
545 | return ret; | |
546 | } | |
547 | ||
548 | static int battery_get_property(struct power_supply *psy, | |
549 | enum power_supply_property psp, union power_supply_propval *val) | |
550 | { | |
551 | int ret = 0; | |
552 | struct battery_data *data = container_of(psy, struct battery_data, psy); | |
553 | ||
554 | switch (psp) { | |
555 | case POWER_SUPPLY_PROP_STATUS: | |
556 | val->intval = data->BAT_STATUS; | |
557 | break; | |
558 | case POWER_SUPPLY_PROP_HEALTH: | |
559 | val->intval = data->BAT_HEALTH; | |
560 | break; | |
561 | case POWER_SUPPLY_PROP_PRESENT: | |
562 | val->intval = data->BAT_PRESENT; | |
563 | break; | |
564 | case POWER_SUPPLY_PROP_TECHNOLOGY: | |
565 | val->intval = data->BAT_TECHNOLOGY; | |
566 | break; | |
567 | case POWER_SUPPLY_PROP_CAPACITY: | |
568 | val->intval = data->BAT_CAPACITY; | |
569 | break; | |
570 | case POWER_SUPPLY_PROP_batt_vol: | |
571 | val->intval = data->BAT_batt_vol; | |
572 | break; | |
573 | case POWER_SUPPLY_PROP_batt_temp: | |
574 | val->intval = data->BAT_batt_temp; | |
575 | break; | |
576 | case POWER_SUPPLY_PROP_TemperatureR: | |
577 | val->intval = data->BAT_TemperatureR; | |
578 | break; | |
579 | case POWER_SUPPLY_PROP_TempBattVoltage: | |
580 | val->intval = data->BAT_TempBattVoltage; | |
581 | break; | |
582 | case POWER_SUPPLY_PROP_InstatVolt: | |
583 | val->intval = data->BAT_InstatVolt; | |
584 | break; | |
585 | case POWER_SUPPLY_PROP_BatteryAverageCurrent: | |
586 | val->intval = data->BAT_BatteryAverageCurrent; | |
587 | break; | |
588 | case POWER_SUPPLY_PROP_BatterySenseVoltage: | |
589 | val->intval = data->BAT_BatterySenseVoltage; | |
590 | break; | |
591 | case POWER_SUPPLY_PROP_ISenseVoltage: | |
592 | val->intval = data->BAT_ISenseVoltage; | |
593 | break; | |
594 | case POWER_SUPPLY_PROP_ChargerVoltage: | |
595 | val->intval = data->BAT_ChargerVoltage; | |
596 | break; | |
597 | /* Dual battery */ | |
598 | case POWER_SUPPLY_PROP_status_smb: | |
599 | val->intval = data->status_smb; | |
600 | break; | |
601 | case POWER_SUPPLY_PROP_capacity_smb: | |
602 | val->intval = data->capacity_smb; | |
603 | break; | |
604 | case POWER_SUPPLY_PROP_present_smb: | |
605 | val->intval = data->present_smb; | |
606 | break; | |
607 | case POWER_SUPPLY_PROP_adjust_power : | |
608 | val->intval = data->adjust_power; | |
609 | break; | |
610 | ||
611 | default: | |
612 | ret = -EINVAL; | |
613 | break; | |
614 | } | |
615 | ||
616 | return ret; | |
617 | } | |
618 | ||
619 | /* wireless_data initialization */ | |
620 | static struct wireless_data wireless_main = { | |
621 | .psy = { | |
622 | .name = "wireless", | |
623 | .type = POWER_SUPPLY_TYPE_WIRELESS, | |
624 | .properties = wireless_props, | |
625 | .num_properties = ARRAY_SIZE(wireless_props), | |
626 | .get_property = wireless_get_property, | |
627 | }, | |
628 | .WIRELESS_ONLINE = 0, | |
629 | }; | |
630 | ||
631 | /* ac_data initialization */ | |
632 | static struct ac_data ac_main = { | |
633 | .psy = { | |
634 | .name = "ac", | |
635 | .type = POWER_SUPPLY_TYPE_MAINS, | |
636 | .properties = ac_props, | |
637 | .num_properties = ARRAY_SIZE(ac_props), | |
638 | .get_property = ac_get_property, | |
639 | }, | |
640 | .AC_ONLINE = 0, | |
641 | }; | |
642 | ||
643 | /* usb_data initialization */ | |
644 | static struct usb_data usb_main = { | |
645 | .psy = { | |
646 | .name = "usb", | |
647 | .type = POWER_SUPPLY_TYPE_USB, | |
648 | .properties = usb_props, | |
649 | .num_properties = ARRAY_SIZE(usb_props), | |
650 | .get_property = usb_get_property, | |
651 | }, | |
652 | .USB_ONLINE = 0, | |
653 | }; | |
654 | ||
655 | /* battery_data initialization */ | |
656 | static struct battery_data battery_main = { | |
657 | .psy = { | |
658 | .name = "battery", | |
659 | .type = POWER_SUPPLY_TYPE_BATTERY, | |
660 | .properties = battery_props, | |
661 | .num_properties = ARRAY_SIZE(battery_props), | |
662 | .get_property = battery_get_property, | |
663 | }, | |
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, | |
668 | .BAT_PRESENT = 1, | |
669 | .BAT_TECHNOLOGY = POWER_SUPPLY_TECHNOLOGY_LION, | |
670 | .BAT_CAPACITY = 100, | |
671 | .BAT_batt_vol = 4200, | |
672 | .BAT_batt_temp = 22, | |
673 | /* Dual battery */ | |
674 | .status_smb = POWER_SUPPLY_STATUS_NOT_CHARGING, | |
675 | .capacity_smb = 50, | |
676 | .present_smb = 0, | |
677 | /* ADB CMD discharging*/ | |
678 | .adjust_power = -1, | |
679 | #else | |
680 | .BAT_STATUS = POWER_SUPPLY_STATUS_NOT_CHARGING, | |
681 | .BAT_HEALTH = POWER_SUPPLY_HEALTH_GOOD, | |
682 | .BAT_PRESENT = 1, | |
683 | .BAT_TECHNOLOGY = POWER_SUPPLY_TECHNOLOGY_LION, | |
684 | #if defined(CONFIG_MTK_PUMP_EXPRESS_SUPPORT) || defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT) | |
685 | .BAT_CAPACITY = -1, | |
686 | #else | |
687 | .BAT_CAPACITY = 50, | |
688 | #endif | |
689 | .BAT_batt_vol = 0, | |
690 | .BAT_batt_temp = 0, | |
691 | /* Dual battery */ | |
692 | .status_smb = POWER_SUPPLY_STATUS_NOT_CHARGING, | |
693 | .capacity_smb = 50, | |
694 | .present_smb = 0, | |
695 | /* ADB CMD discharging*/ | |
696 | .adjust_power = -1, | |
697 | #endif | |
698 | }; | |
699 | ||
700 | ||
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, | |
706 | char *buf) | |
707 | { | |
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); | |
711 | } | |
712 | ||
713 | static ssize_t store_ADC_Charger_Voltage(struct device *dev, struct device_attribute *attr, | |
714 | const char *buf, size_t size) | |
715 | { | |
716 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
717 | return size; | |
718 | } | |
719 | ||
720 | static DEVICE_ATTR(ADC_Charger_Voltage, 0664, show_ADC_Charger_Voltage, store_ADC_Charger_Voltage); | |
721 | ||
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, | |
726 | char *buf) | |
727 | { | |
728 | int ret_value = 1; | |
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); | |
732 | } | |
733 | ||
734 | static ssize_t store_ADC_Channel_0_Slope(struct device *dev, struct device_attribute *attr, | |
735 | const char *buf, size_t size) | |
736 | { | |
737 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
738 | return size; | |
739 | } | |
740 | ||
741 | static DEVICE_ATTR(ADC_Channel_0_Slope, 0664, show_ADC_Channel_0_Slope, store_ADC_Channel_0_Slope); | |
742 | ||
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, | |
747 | char *buf) | |
748 | { | |
749 | int ret_value = 1; | |
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); | |
753 | } | |
754 | ||
755 | static ssize_t store_ADC_Channel_1_Slope(struct device *dev, struct device_attribute *attr, | |
756 | const char *buf, size_t size) | |
757 | { | |
758 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
759 | return size; | |
760 | } | |
761 | ||
762 | static DEVICE_ATTR(ADC_Channel_1_Slope, 0664, show_ADC_Channel_1_Slope, store_ADC_Channel_1_Slope); | |
763 | ||
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, | |
768 | char *buf) | |
769 | { | |
770 | int ret_value = 1; | |
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); | |
774 | } | |
775 | ||
776 | static ssize_t store_ADC_Channel_2_Slope(struct device *dev, struct device_attribute *attr, | |
777 | const char *buf, size_t size) | |
778 | { | |
779 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
780 | return size; | |
781 | } | |
782 | ||
783 | static DEVICE_ATTR(ADC_Channel_2_Slope, 0664, show_ADC_Channel_2_Slope, store_ADC_Channel_2_Slope); | |
784 | ||
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, | |
789 | char *buf) | |
790 | { | |
791 | int ret_value = 1; | |
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); | |
795 | } | |
796 | ||
797 | static ssize_t store_ADC_Channel_3_Slope(struct device *dev, struct device_attribute *attr, | |
798 | const char *buf, size_t size) | |
799 | { | |
800 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
801 | return size; | |
802 | } | |
803 | ||
804 | static DEVICE_ATTR(ADC_Channel_3_Slope, 0664, show_ADC_Channel_3_Slope, store_ADC_Channel_3_Slope); | |
805 | ||
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, | |
810 | char *buf) | |
811 | { | |
812 | int ret_value = 1; | |
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); | |
816 | } | |
817 | ||
818 | static ssize_t store_ADC_Channel_4_Slope(struct device *dev, struct device_attribute *attr, | |
819 | const char *buf, size_t size) | |
820 | { | |
821 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
822 | return size; | |
823 | } | |
824 | ||
825 | static DEVICE_ATTR(ADC_Channel_4_Slope, 0664, show_ADC_Channel_4_Slope, store_ADC_Channel_4_Slope); | |
826 | ||
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, | |
831 | char *buf) | |
832 | { | |
833 | int ret_value = 1; | |
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); | |
837 | } | |
838 | ||
839 | static ssize_t store_ADC_Channel_5_Slope(struct device *dev, struct device_attribute *attr, | |
840 | const char *buf, size_t size) | |
841 | { | |
842 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
843 | return size; | |
844 | } | |
845 | ||
846 | static DEVICE_ATTR(ADC_Channel_5_Slope, 0664, show_ADC_Channel_5_Slope, store_ADC_Channel_5_Slope); | |
847 | ||
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, | |
852 | char *buf) | |
853 | { | |
854 | int ret_value = 1; | |
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); | |
858 | } | |
859 | ||
860 | static ssize_t store_ADC_Channel_6_Slope(struct device *dev, struct device_attribute *attr, | |
861 | const char *buf, size_t size) | |
862 | { | |
863 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
864 | return size; | |
865 | } | |
866 | ||
867 | static DEVICE_ATTR(ADC_Channel_6_Slope, 0664, show_ADC_Channel_6_Slope, store_ADC_Channel_6_Slope); | |
868 | ||
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, | |
873 | char *buf) | |
874 | { | |
875 | int ret_value = 1; | |
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); | |
879 | } | |
880 | ||
881 | static ssize_t store_ADC_Channel_7_Slope(struct device *dev, struct device_attribute *attr, | |
882 | const char *buf, size_t size) | |
883 | { | |
884 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
885 | return size; | |
886 | } | |
887 | ||
888 | static DEVICE_ATTR(ADC_Channel_7_Slope, 0664, show_ADC_Channel_7_Slope, store_ADC_Channel_7_Slope); | |
889 | ||
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, | |
894 | char *buf) | |
895 | { | |
896 | int ret_value = 1; | |
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); | |
900 | } | |
901 | ||
902 | static ssize_t store_ADC_Channel_8_Slope(struct device *dev, struct device_attribute *attr, | |
903 | const char *buf, size_t size) | |
904 | { | |
905 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
906 | return size; | |
907 | } | |
908 | ||
909 | static DEVICE_ATTR(ADC_Channel_8_Slope, 0664, show_ADC_Channel_8_Slope, store_ADC_Channel_8_Slope); | |
910 | ||
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, | |
915 | char *buf) | |
916 | { | |
917 | int ret_value = 1; | |
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); | |
921 | } | |
922 | ||
923 | static ssize_t store_ADC_Channel_9_Slope(struct device *dev, struct device_attribute *attr, | |
924 | const char *buf, size_t size) | |
925 | { | |
926 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
927 | return size; | |
928 | } | |
929 | ||
930 | static DEVICE_ATTR(ADC_Channel_9_Slope, 0664, show_ADC_Channel_9_Slope, store_ADC_Channel_9_Slope); | |
931 | ||
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, | |
936 | char *buf) | |
937 | { | |
938 | int ret_value = 1; | |
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); | |
942 | } | |
943 | ||
944 | static ssize_t store_ADC_Channel_10_Slope(struct device *dev, struct device_attribute *attr, | |
945 | const char *buf, size_t size) | |
946 | { | |
947 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
948 | return size; | |
949 | } | |
950 | ||
951 | static DEVICE_ATTR(ADC_Channel_10_Slope, 0664, show_ADC_Channel_10_Slope, | |
952 | store_ADC_Channel_10_Slope); | |
953 | ||
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, | |
958 | char *buf) | |
959 | { | |
960 | int ret_value = 1; | |
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); | |
964 | } | |
965 | ||
966 | static ssize_t store_ADC_Channel_11_Slope(struct device *dev, struct device_attribute *attr, | |
967 | const char *buf, size_t size) | |
968 | { | |
969 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
970 | return size; | |
971 | } | |
972 | ||
973 | static DEVICE_ATTR(ADC_Channel_11_Slope, 0664, show_ADC_Channel_11_Slope, | |
974 | store_ADC_Channel_11_Slope); | |
975 | ||
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, | |
980 | char *buf) | |
981 | { | |
982 | int ret_value = 1; | |
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); | |
986 | } | |
987 | ||
988 | static ssize_t store_ADC_Channel_12_Slope(struct device *dev, struct device_attribute *attr, | |
989 | const char *buf, size_t size) | |
990 | { | |
991 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
992 | return size; | |
993 | } | |
994 | ||
995 | static DEVICE_ATTR(ADC_Channel_12_Slope, 0664, show_ADC_Channel_12_Slope, | |
996 | store_ADC_Channel_12_Slope); | |
997 | ||
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, | |
1002 | char *buf) | |
1003 | { | |
1004 | int ret_value = 1; | |
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); | |
1008 | } | |
1009 | ||
1010 | static ssize_t store_ADC_Channel_13_Slope(struct device *dev, struct device_attribute *attr, | |
1011 | const char *buf, size_t size) | |
1012 | { | |
1013 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1014 | return size; | |
1015 | } | |
1016 | ||
1017 | static DEVICE_ATTR(ADC_Channel_13_Slope, 0664, show_ADC_Channel_13_Slope, | |
1018 | store_ADC_Channel_13_Slope); | |
1019 | ||
1020 | ||
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, | |
1025 | char *buf) | |
1026 | { | |
1027 | int ret_value = 1; | |
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); | |
1031 | } | |
1032 | ||
1033 | static ssize_t store_ADC_Channel_0_Offset(struct device *dev, struct device_attribute *attr, | |
1034 | const char *buf, size_t size) | |
1035 | { | |
1036 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1037 | return size; | |
1038 | } | |
1039 | ||
1040 | static DEVICE_ATTR(ADC_Channel_0_Offset, 0664, show_ADC_Channel_0_Offset, | |
1041 | store_ADC_Channel_0_Offset); | |
1042 | ||
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, | |
1047 | char *buf) | |
1048 | { | |
1049 | int ret_value = 1; | |
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); | |
1053 | } | |
1054 | ||
1055 | static ssize_t store_ADC_Channel_1_Offset(struct device *dev, struct device_attribute *attr, | |
1056 | const char *buf, size_t size) | |
1057 | { | |
1058 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1059 | return size; | |
1060 | } | |
1061 | ||
1062 | static DEVICE_ATTR(ADC_Channel_1_Offset, 0664, show_ADC_Channel_1_Offset, | |
1063 | store_ADC_Channel_1_Offset); | |
1064 | ||
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, | |
1069 | char *buf) | |
1070 | { | |
1071 | int ret_value = 1; | |
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); | |
1075 | } | |
1076 | ||
1077 | static ssize_t store_ADC_Channel_2_Offset(struct device *dev, struct device_attribute *attr, | |
1078 | const char *buf, size_t size) | |
1079 | { | |
1080 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1081 | return size; | |
1082 | } | |
1083 | ||
1084 | static DEVICE_ATTR(ADC_Channel_2_Offset, 0664, show_ADC_Channel_2_Offset, | |
1085 | store_ADC_Channel_2_Offset); | |
1086 | ||
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, | |
1091 | char *buf) | |
1092 | { | |
1093 | int ret_value = 1; | |
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); | |
1097 | } | |
1098 | ||
1099 | static ssize_t store_ADC_Channel_3_Offset(struct device *dev, struct device_attribute *attr, | |
1100 | const char *buf, size_t size) | |
1101 | { | |
1102 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1103 | return size; | |
1104 | } | |
1105 | ||
1106 | static DEVICE_ATTR(ADC_Channel_3_Offset, 0664, show_ADC_Channel_3_Offset, | |
1107 | store_ADC_Channel_3_Offset); | |
1108 | ||
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, | |
1113 | char *buf) | |
1114 | { | |
1115 | int ret_value = 1; | |
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); | |
1119 | } | |
1120 | ||
1121 | static ssize_t store_ADC_Channel_4_Offset(struct device *dev, struct device_attribute *attr, | |
1122 | const char *buf, size_t size) | |
1123 | { | |
1124 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1125 | return size; | |
1126 | } | |
1127 | ||
1128 | static DEVICE_ATTR(ADC_Channel_4_Offset, 0664, show_ADC_Channel_4_Offset, | |
1129 | store_ADC_Channel_4_Offset); | |
1130 | ||
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, | |
1135 | char *buf) | |
1136 | { | |
1137 | int ret_value = 1; | |
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); | |
1141 | } | |
1142 | ||
1143 | static ssize_t store_ADC_Channel_5_Offset(struct device *dev, struct device_attribute *attr, | |
1144 | const char *buf, size_t size) | |
1145 | { | |
1146 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1147 | return size; | |
1148 | } | |
1149 | ||
1150 | static DEVICE_ATTR(ADC_Channel_5_Offset, 0664, show_ADC_Channel_5_Offset, | |
1151 | store_ADC_Channel_5_Offset); | |
1152 | ||
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, | |
1157 | char *buf) | |
1158 | { | |
1159 | int ret_value = 1; | |
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); | |
1163 | } | |
1164 | ||
1165 | static ssize_t store_ADC_Channel_6_Offset(struct device *dev, struct device_attribute *attr, | |
1166 | const char *buf, size_t size) | |
1167 | { | |
1168 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1169 | return size; | |
1170 | } | |
1171 | ||
1172 | static DEVICE_ATTR(ADC_Channel_6_Offset, 0664, show_ADC_Channel_6_Offset, | |
1173 | store_ADC_Channel_6_Offset); | |
1174 | ||
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, | |
1179 | char *buf) | |
1180 | { | |
1181 | int ret_value = 1; | |
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); | |
1185 | } | |
1186 | ||
1187 | static ssize_t store_ADC_Channel_7_Offset(struct device *dev, struct device_attribute *attr, | |
1188 | const char *buf, size_t size) | |
1189 | { | |
1190 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1191 | return size; | |
1192 | } | |
1193 | ||
1194 | static DEVICE_ATTR(ADC_Channel_7_Offset, 0664, show_ADC_Channel_7_Offset, | |
1195 | store_ADC_Channel_7_Offset); | |
1196 | ||
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, | |
1201 | char *buf) | |
1202 | { | |
1203 | int ret_value = 1; | |
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); | |
1207 | } | |
1208 | ||
1209 | static ssize_t store_ADC_Channel_8_Offset(struct device *dev, struct device_attribute *attr, | |
1210 | const char *buf, size_t size) | |
1211 | { | |
1212 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1213 | return size; | |
1214 | } | |
1215 | ||
1216 | static DEVICE_ATTR(ADC_Channel_8_Offset, 0664, show_ADC_Channel_8_Offset, | |
1217 | store_ADC_Channel_8_Offset); | |
1218 | ||
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, | |
1223 | char *buf) | |
1224 | { | |
1225 | int ret_value = 1; | |
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); | |
1229 | } | |
1230 | ||
1231 | static ssize_t store_ADC_Channel_9_Offset(struct device *dev, struct device_attribute *attr, | |
1232 | const char *buf, size_t size) | |
1233 | { | |
1234 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1235 | return size; | |
1236 | } | |
1237 | ||
1238 | static DEVICE_ATTR(ADC_Channel_9_Offset, 0664, show_ADC_Channel_9_Offset, | |
1239 | store_ADC_Channel_9_Offset); | |
1240 | ||
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, | |
1245 | char *buf) | |
1246 | { | |
1247 | int ret_value = 1; | |
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); | |
1251 | } | |
1252 | ||
1253 | static ssize_t store_ADC_Channel_10_Offset(struct device *dev, struct device_attribute *attr, | |
1254 | const char *buf, size_t size) | |
1255 | { | |
1256 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1257 | return size; | |
1258 | } | |
1259 | ||
1260 | static DEVICE_ATTR(ADC_Channel_10_Offset, 0664, show_ADC_Channel_10_Offset, | |
1261 | store_ADC_Channel_10_Offset); | |
1262 | ||
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, | |
1267 | char *buf) | |
1268 | { | |
1269 | int ret_value = 1; | |
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); | |
1273 | } | |
1274 | ||
1275 | static ssize_t store_ADC_Channel_11_Offset(struct device *dev, struct device_attribute *attr, | |
1276 | const char *buf, size_t size) | |
1277 | { | |
1278 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1279 | return size; | |
1280 | } | |
1281 | ||
1282 | static DEVICE_ATTR(ADC_Channel_11_Offset, 0664, show_ADC_Channel_11_Offset, | |
1283 | store_ADC_Channel_11_Offset); | |
1284 | ||
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, | |
1289 | char *buf) | |
1290 | { | |
1291 | int ret_value = 1; | |
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); | |
1295 | } | |
1296 | ||
1297 | static ssize_t store_ADC_Channel_12_Offset(struct device *dev, struct device_attribute *attr, | |
1298 | const char *buf, size_t size) | |
1299 | { | |
1300 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1301 | return size; | |
1302 | } | |
1303 | ||
1304 | static DEVICE_ATTR(ADC_Channel_12_Offset, 0664, show_ADC_Channel_12_Offset, | |
1305 | store_ADC_Channel_12_Offset); | |
1306 | ||
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, | |
1311 | char *buf) | |
1312 | { | |
1313 | int ret_value = 1; | |
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); | |
1317 | } | |
1318 | ||
1319 | static ssize_t store_ADC_Channel_13_Offset(struct device *dev, struct device_attribute *attr, | |
1320 | const char *buf, size_t size) | |
1321 | { | |
1322 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1323 | return size; | |
1324 | } | |
1325 | ||
1326 | static DEVICE_ATTR(ADC_Channel_13_Offset, 0664, show_ADC_Channel_13_Offset, | |
1327 | store_ADC_Channel_13_Offset); | |
1328 | ||
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, | |
1333 | char *buf) | |
1334 | { | |
1335 | int ret_value = 2; | |
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); | |
1339 | } | |
1340 | ||
1341 | static ssize_t store_ADC_Channel_Is_Calibration(struct device *dev, struct device_attribute *attr, | |
1342 | const char *buf, size_t size) | |
1343 | { | |
1344 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1345 | return size; | |
1346 | } | |
1347 | ||
1348 | static DEVICE_ATTR(ADC_Channel_Is_Calibration, 0664, show_ADC_Channel_Is_Calibration, | |
1349 | store_ADC_Channel_Is_Calibration); | |
1350 | ||
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) | |
1355 | { | |
1356 | int ret_value = 1; | |
1357 | ret_value = 3400; | |
1358 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Power_On_Voltage : %d\n", ret_value); | |
1359 | return sprintf(buf, "%u\n", ret_value); | |
1360 | } | |
1361 | ||
1362 | static ssize_t store_Power_On_Voltage(struct device *dev, struct device_attribute *attr, | |
1363 | const char *buf, size_t size) | |
1364 | { | |
1365 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1366 | return size; | |
1367 | } | |
1368 | ||
1369 | static DEVICE_ATTR(Power_On_Voltage, 0664, show_Power_On_Voltage, store_Power_On_Voltage); | |
1370 | ||
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) | |
1375 | { | |
1376 | int ret_value = 1; | |
1377 | ret_value = 3400; | |
1378 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Power_Off_Voltage : %d\n", ret_value); | |
1379 | return sprintf(buf, "%u\n", ret_value); | |
1380 | } | |
1381 | ||
1382 | static ssize_t store_Power_Off_Voltage(struct device *dev, struct device_attribute *attr, | |
1383 | const char *buf, size_t size) | |
1384 | { | |
1385 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1386 | return size; | |
1387 | } | |
1388 | ||
1389 | static DEVICE_ATTR(Power_Off_Voltage, 0664, show_Power_Off_Voltage, store_Power_Off_Voltage); | |
1390 | ||
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, | |
1395 | char *buf) | |
1396 | { | |
1397 | int ret_value = 1; | |
1398 | ret_value = 4110; | |
1399 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Charger_TopOff_Value : %d\n", ret_value); | |
1400 | return sprintf(buf, "%u\n", ret_value); | |
1401 | } | |
1402 | ||
1403 | static ssize_t store_Charger_TopOff_Value(struct device *dev, struct device_attribute *attr, | |
1404 | const char *buf, size_t size) | |
1405 | { | |
1406 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1407 | return size; | |
1408 | } | |
1409 | ||
1410 | static DEVICE_ATTR(Charger_TopOff_Value, 0664, show_Charger_TopOff_Value, | |
1411 | store_Charger_TopOff_Value); | |
1412 | ||
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, | |
1417 | char *buf) | |
1418 | { | |
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", | |
1422 | ret_value); | |
1423 | return sprintf(buf, "%u\n", ret_value); | |
1424 | } | |
1425 | ||
1426 | static ssize_t store_FG_Battery_CurrentConsumption(struct device *dev, | |
1427 | struct device_attribute *attr, const char *buf, | |
1428 | size_t size) | |
1429 | { | |
1430 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1431 | return size; | |
1432 | } | |
1433 | ||
1434 | static DEVICE_ATTR(FG_Battery_CurrentConsumption, 0664, show_FG_Battery_CurrentConsumption, | |
1435 | store_FG_Battery_CurrentConsumption); | |
1436 | ||
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, | |
1441 | char *buf) | |
1442 | { | |
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); | |
1447 | } | |
1448 | ||
1449 | static ssize_t store_FG_SW_CoulombCounter(struct device *dev, struct device_attribute *attr, | |
1450 | const char *buf, size_t size) | |
1451 | { | |
1452 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1453 | return size; | |
1454 | } | |
1455 | ||
1456 | static DEVICE_ATTR(FG_SW_CoulombCounter, 0664, show_FG_SW_CoulombCounter, | |
1457 | store_FG_SW_CoulombCounter); | |
1458 | ||
1459 | ||
1460 | static ssize_t show_Charging_CallState(struct device *dev, struct device_attribute *attr, char *buf) | |
1461 | { | |
1462 | battery_xlog_printk(BAT_LOG_CRTI, "call state = %d\n", g_call_state); | |
1463 | return sprintf(buf, "%u\n", g_call_state); | |
1464 | } | |
1465 | ||
1466 | static ssize_t store_Charging_CallState(struct device *dev, struct device_attribute *attr, | |
1467 | const char *buf, size_t size) | |
1468 | { | |
1469 | sscanf(buf, "%u", &g_call_state); | |
1470 | battery_xlog_printk(BAT_LOG_CRTI, "call state = %d\n", g_call_state); | |
1471 | return size; | |
1472 | } | |
1473 | ||
1474 | static DEVICE_ATTR(Charging_CallState, 0664, show_Charging_CallState, store_Charging_CallState); | |
1475 | ||
1476 | static ssize_t show_Charger_Type(struct device *dev,struct device_attribute *attr, | |
1477 | char *buf) | |
1478 | { | |
1479 | UINT32 chr_ype = CHARGER_UNKNOWN; | |
1480 | chr_ype = BMT_status.charger_exist ? BMT_status.charger_type : CHARGER_UNKNOWN; | |
1481 | ||
1482 | battery_xlog_printk(BAT_LOG_CRTI, "CHARGER_TYPE = %d\n",chr_ype); | |
1483 | return sprintf(buf, "%u\n", chr_ype); | |
1484 | } | |
1485 | static ssize_t store_Charger_Type(struct device *dev,struct device_attribute *attr, const char *buf, size_t size) | |
1486 | { | |
1487 | battery_xlog_printk(BAT_LOG_CRTI, "[EM] Not Support Write Function\n"); | |
1488 | return size; | |
1489 | } | |
1490 | static DEVICE_ATTR(Charger_Type, 0664, show_Charger_Type, store_Charger_Type); | |
1491 | ||
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, | |
1494 | char *buf) | |
1495 | { | |
1496 | #if defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT) | |
1497 | int icount = 20; //max debouncing time 20 * 0.2 sec | |
1498 | ||
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) | |
1503 | { | |
1504 | battery_xlog_printk(BAT_LOG_CRTI, "[%s]Wait for PE detection\n", __func__); | |
1505 | do | |
1506 | { | |
1507 | icount--; | |
1508 | msleep(200); | |
1509 | }while(icount && ta_check_chr_type); | |
1510 | } | |
1511 | #endif | |
1512 | ||
1513 | #if defined(CONFIG_MTK_PUMP_EXPRESS_SUPPORT) | |
1514 | ||
1515 | if ( (KAL_TRUE == ta_check_chr_type) && | |
1516 | (STANDARD_CHARGER == BMT_status.charger_type) ) | |
1517 | { | |
1518 | battery_xlog_printk(BAT_LOG_CRTI, "[%s]Wait for PE detection\n", __func__); | |
1519 | do | |
1520 | { | |
1521 | msleep(200); | |
1522 | }while(ta_check_chr_type); | |
1523 | } | |
1524 | #endif | |
1525 | battery_xlog_printk(BAT_LOG_CRTI, "Pump express = %d\n",is_ta_connect); | |
1526 | return sprintf(buf, "%u\n", is_ta_connect); | |
1527 | } | |
1528 | static ssize_t store_Pump_Express(struct device *dev,struct device_attribute *attr, const char *buf, size_t size) | |
1529 | { | |
1530 | sscanf(buf, "%u", &is_ta_connect); | |
1531 | battery_xlog_printk(BAT_LOG_CRTI, "Pump express= %d\n",is_ta_connect); | |
1532 | return size; | |
1533 | } | |
1534 | static DEVICE_ATTR(Pump_Express, 0664, show_Pump_Express, store_Pump_Express); | |
1535 | #endif | |
1536 | ||
1537 | static void mt_battery_update_EM(struct battery_data *bat_data) | |
1538 | { | |
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; | |
1547 | /* Dual battery */ | |
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; | |
1555 | ||
1556 | #ifdef CONFIG_MTK_DISABLE_POWER_ON_OFF_VOLTAGE_LIMITATION | |
1557 | if (bat_data->BAT_CAPACITY <= 0) | |
1558 | bat_data->BAT_CAPACITY = 1; | |
1559 | ||
1560 | battery_xlog_printk(BAT_LOG_CRTI, | |
1561 | "BAT_CAPACITY=1, due to define CONFIG_MTK_DISABLE_POWER_ON_OFF_VOLTAGE_LIMITATION\r\n"); | |
1562 | #endif | |
1563 | } | |
1564 | ||
1565 | ||
1566 | static kal_bool mt_battery_100Percent_tracking_check(void) | |
1567 | { | |
1568 | kal_bool resetBatteryMeter = KAL_FALSE; | |
1569 | ||
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); | |
1573 | #else | |
1574 | kal_uint32 cust_sync_time = ONEHUNDRED_PERCENT_TRACKING_TIME; | |
1575 | static kal_uint32 timer_counter = (ONEHUNDRED_PERCENT_TRACKING_TIME / BAT_TASK_PERIOD); | |
1576 | #endif | |
1577 | ||
1578 | if (BMT_status.bat_full == KAL_TRUE) /* charging full first, UI tracking to 100% */ | |
1579 | { | |
1580 | if (BMT_status.UI_SOC >= 100) { | |
1581 | BMT_status.UI_SOC = 100; | |
1582 | ||
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; | |
1587 | } else { | |
1588 | resetBatteryMeter = KAL_FALSE; | |
1589 | } | |
1590 | } else { | |
1591 | /* increase UI percentage every xxs */ | |
1592 | if (timer_counter >= (cust_sync_time / BAT_TASK_PERIOD)) { | |
1593 | timer_counter = 1; | |
1594 | BMT_status.UI_SOC++; | |
1595 | } else { | |
1596 | timer_counter++; | |
1597 | ||
1598 | return resetBatteryMeter; | |
1599 | } | |
1600 | ||
1601 | resetBatteryMeter = KAL_TRUE; | |
1602 | } | |
1603 | ||
1604 | battery_xlog_printk(BAT_LOG_CRTI, "[100percent], UI_SOC(%d), reset(%d)\n", | |
1605 | BMT_status.UI_SOC, resetBatteryMeter); | |
1606 | } else { | |
1607 | /* charging is not full, UI keep 99% if reaching 100%, */ | |
1608 | ||
1609 | if (BMT_status.UI_SOC >= 99) { | |
1610 | BMT_status.UI_SOC = 99; | |
1611 | resetBatteryMeter = KAL_FALSE; | |
1612 | ||
1613 | battery_xlog_printk(BAT_LOG_CRTI, "[100percent],UI_SOC = %d\n", | |
1614 | BMT_status.UI_SOC); | |
1615 | } | |
1616 | ||
1617 | timer_counter = (cust_sync_time / BAT_TASK_PERIOD); | |
1618 | ||
1619 | } | |
1620 | ||
1621 | return resetBatteryMeter; | |
1622 | } | |
1623 | ||
1624 | ||
1625 | static kal_bool mt_battery_nPercent_tracking_check(void) | |
1626 | { | |
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); | |
1630 | ||
1631 | if (BMT_status.nPrecent_UI_SOC_check_point == 0) | |
1632 | return KAL_FALSE; | |
1633 | ||
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 */ | |
1638 | { | |
1639 | BMT_status.UI_SOC--; | |
1640 | timer_counter = 1; | |
1641 | } else { | |
1642 | timer_counter++; | |
1643 | return resetBatteryMeter; | |
1644 | } | |
1645 | ||
1646 | resetBatteryMeter = KAL_TRUE; | |
1647 | ||
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; | |
1657 | ||
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); | |
1662 | } else { | |
1663 | timer_counter = (NPERCENT_TRACKING_TIME / BAT_TASK_PERIOD); | |
1664 | } | |
1665 | #endif | |
1666 | return resetBatteryMeter; | |
1667 | ||
1668 | } | |
1669 | ||
1670 | static kal_bool mt_battery_0Percent_tracking_check(void) | |
1671 | { | |
1672 | kal_bool resetBatteryMeter = KAL_TRUE; | |
1673 | ||
1674 | if (BMT_status.UI_SOC <= 0) { | |
1675 | BMT_status.UI_SOC = 0; | |
1676 | } else { | |
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--; | |
1681 | } | |
1682 | } | |
1683 | ||
1684 | battery_xlog_printk(BAT_LOG_CRTI, "0Percent, VBAT < %d UI_SOC=%d\r\n", SYSTEM_OFF_VOLTAGE, | |
1685 | BMT_status.UI_SOC); | |
1686 | ||
1687 | return resetBatteryMeter; | |
1688 | } | |
1689 | ||
1690 | ||
1691 | static void mt_battery_Sync_UI_Percentage_to_Real(void) | |
1692 | { | |
1693 | static kal_uint32 timer_counter; | |
1694 | ||
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; | |
1699 | ||
1700 | if (sleep_timer > 80) //80 s | |
1701 | { | |
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); | |
1704 | ||
1705 | if (soc_reduce_step > (BMT_status.UI_SOC - BMT_status.SOC)) | |
1706 | { | |
1707 | BMT_status.UI_SOC = BMT_status.SOC; | |
1708 | } | |
1709 | else | |
1710 | { | |
1711 | BMT_status.UI_SOC = BMT_status.UI_SOC - soc_reduce_step; | |
1712 | } | |
1713 | } | |
1714 | else | |
1715 | { | |
1716 | /* reduce after xxs */ | |
1717 | if (timer_counter == (SYNC_TO_REAL_TRACKING_TIME / BAT_TASK_PERIOD)) { | |
1718 | BMT_status.UI_SOC--; | |
1719 | timer_counter = 0; | |
1720 | } else { | |
1721 | timer_counter++; | |
1722 | } | |
1723 | } | |
1724 | /*[BUGFIX]-Add-END by TCTSZ.pingao.yang */ | |
1725 | #else | |
1726 | BMT_status.UI_SOC--; | |
1727 | #endif | |
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); | |
1730 | } else { | |
1731 | timer_counter = 0; | |
1732 | ||
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)) | |
1735 | { | |
1736 | if( upmu_is_chr_det() == KAL_TRUE ) | |
1737 | BMT_status.UI_SOC++; | |
1738 | } | |
1739 | else | |
1740 | { | |
1741 | BMT_status.UI_SOC = BMT_status.SOC; | |
1742 | } | |
1743 | #else | |
1744 | BMT_status.UI_SOC = BMT_status.SOC; | |
1745 | #endif | |
1746 | } | |
1747 | ||
1748 | /* [PLATFORM]-Add-BEGIN by TCTSZ.pingao.yang, 2015.03.30, refer pr 951694 */ | |
1749 | #if 0 | |
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", | |
1753 | BMT_status.UI_SOC); | |
1754 | } | |
1755 | #endif | |
1756 | /* [PLATFORM]-Add-END by TCTSZ.pingao.yang, 2015.03.30 */ | |
1757 | ||
1758 | } | |
1759 | ||
1760 | static void battery_update(struct battery_data *bat_data) | |
1761 | { | |
1762 | struct power_supply *bat_psy = &bat_data->psy; | |
1763 | kal_bool resetBatteryMeter = KAL_FALSE; | |
1764 | ||
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 ){ | |
1769 | case TEMP_POS_LOW: | |
1770 | bat_data->BAT_HEALTH = POWER_SUPPLY_HEALTH_COLD; | |
1771 | break; | |
1772 | case TEMP_POS_NORMAL: | |
1773 | bat_data->BAT_HEALTH = POWER_SUPPLY_HEALTH_GOOD; | |
1774 | break; | |
1775 | case TEMP_POS_HIGH: | |
1776 | bat_data->BAT_HEALTH = POWER_SUPPLY_HEALTH_OVERHEAT; | |
1777 | break; | |
1778 | default: | |
1779 | bat_data->BAT_HEALTH = POWER_SUPPLY_HEALTH_UNKNOWN; | |
1780 | break; | |
1781 | } | |
1782 | #else | |
1783 | bat_data->BAT_HEALTH = POWER_SUPPLY_HEALTH_GOOD; | |
1784 | #endif | |
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; | |
1789 | ||
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 */ | |
1793 | ||
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(); | |
1798 | } else { | |
1799 | resetBatteryMeter = mt_battery_100Percent_tracking_check(); | |
1800 | } | |
1801 | ||
1802 | bat_data->BAT_STATUS = POWER_SUPPLY_STATUS_CHARGING; | |
1803 | } else { /* No Battery, Only Charger */ | |
1804 | ||
1805 | bat_data->BAT_STATUS = POWER_SUPPLY_STATUS_UNKNOWN; | |
1806 | BMT_status.UI_SOC = 0; | |
1807 | } | |
1808 | ||
1809 | } else { /* Only Battery */ | |
1810 | ||
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(); | |
1814 | else | |
1815 | resetBatteryMeter = mt_battery_nPercent_tracking_check(); | |
1816 | } | |
1817 | ||
1818 | if (resetBatteryMeter == KAL_TRUE) { | |
1819 | battery_meter_reset(); | |
1820 | } else { | |
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); | |
1825 | } else { | |
1826 | mt_battery_Sync_UI_Percentage_to_Real(); | |
1827 | } | |
1828 | } | |
1829 | ||
1830 | battery_xlog_printk(BAT_LOG_CRTI, "UI_SOC=(%d), resetBatteryMeter=(%d)\n", | |
1831 | BMT_status.UI_SOC, resetBatteryMeter); | |
4b9e9796 S |
1832 | |
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 | |
6fa3eb70 S |
1837 | //restore battery UI capacity to rtc |
1838 | if (battery_meter_get_battery_soc() <= 1) { | |
1839 | set_rtc_spare_fg_value(1); | |
1840 | } | |
1841 | else { | |
1842 | set_rtc_spare_fg_value(battery_meter_get_battery_soc()); /*use battery_soc*/ | |
1843 | } | |
1844 | #else | |
1845 | ||
6fa3eb70 S |
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); | |
1849 | } else { | |
1850 | set_rtc_spare_fg_value(BMT_status.UI_SOC); | |
1851 | } | |
1852 | #endif | |
1853 | ||
1854 | mt_battery_update_EM(bat_data); | |
1855 | ||
1856 | if (cmd_discharging == 1) { | |
1857 | bat_data->BAT_STATUS = POWER_SUPPLY_STATUS_CMD_DISCHARGING; | |
1858 | } | |
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); | |
1862 | } | |
1863 | ||
1864 | power_supply_changed(bat_psy); | |
1865 | } | |
1866 | ||
1867 | void update_charger_info(int wireless_state) | |
1868 | { | |
1869 | #if defined(CONFIG_POWER_VERIFY) | |
1870 | battery_xlog_printk(BAT_LOG_CRTI, "[update_charger_info] no support\n"); | |
1871 | #else | |
1872 | g_wireless_state = wireless_state; | |
1873 | battery_xlog_printk(BAT_LOG_CRTI, "[update_charger_info] get wireless_state=%d\n", | |
1874 | wireless_state); | |
1875 | ||
1876 | wake_up_bat(); | |
1877 | #endif | |
1878 | } | |
1879 | ||
1880 | static void wireless_update(struct wireless_data *wireless_data) | |
1881 | { | |
1882 | struct power_supply *wireless_psy = &wireless_data->psy; | |
1883 | ||
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; | |
1888 | } else { | |
1889 | wireless_data->WIRELESS_ONLINE = 0; | |
1890 | } | |
1891 | } else { | |
1892 | wireless_data->WIRELESS_ONLINE = 0; | |
1893 | } | |
1894 | ||
1895 | power_supply_changed(wireless_psy); | |
1896 | } | |
1897 | ||
1898 | static void ac_update(struct ac_data *ac_data) | |
1899 | { | |
1900 | struct power_supply *ac_psy = &ac_data->psy; | |
1901 | ||
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)) { | |
1909 | #else | |
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)) { | |
1916 | #endif | |
1917 | ac_data->AC_ONLINE = 1; | |
1918 | ac_psy->type = POWER_SUPPLY_TYPE_MAINS; | |
1919 | } else { | |
1920 | ac_data->AC_ONLINE = 0; | |
1921 | } | |
1922 | } else { | |
1923 | ac_data->AC_ONLINE = 0; | |
1924 | } | |
1925 | ||
1926 | power_supply_changed(ac_psy); | |
1927 | } | |
1928 | ||
1929 | static void usb_update(struct usb_data *usb_data) | |
1930 | { | |
1931 | struct power_supply *usb_psy = &usb_data->psy; | |
1932 | ||
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; | |
1938 | } else { | |
1939 | usb_data->USB_ONLINE = 0; | |
1940 | } | |
1941 | } else { | |
1942 | usb_data->USB_ONLINE = 0; | |
1943 | } | |
1944 | ||
1945 | power_supply_changed(usb_psy); | |
1946 | } | |
1947 | ||
1948 | #endif | |
1949 | ||
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) | |
1955 | { | |
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", | |
1959 | battery_temp); | |
1960 | ||
1961 | return count; | |
1962 | } | |
1963 | ||
1964 | static ssize_t chg_ntc_debugfs_show(struct device *dev, struct device_attribute *attr, | |
1965 | char *buf) | |
1966 | { | |
1967 | return sprintf(buf, "battery_temp = %d\n", battery_temp); | |
1968 | } | |
1969 | ||
1970 | static DEVICE_ATTR(ntc_debug, 0644, chg_ntc_debugfs_show, chg_ntc_debugfs_store); | |
1971 | #endif | |
1972 | /* [PLATFORM]-Add-END by TCTSZ.leo.guo */ | |
1973 | ||
1974 | /* ///////////////////////////////////////////////////////////////////////////////////////// */ | |
1975 | /* // Battery Temprature Parameters and functions */ | |
1976 | /* ///////////////////////////////////////////////////////////////////////////////////////// */ | |
1977 | kal_bool pmic_chrdet_status(void) | |
1978 | { | |
1979 | if (upmu_is_chr_det() == KAL_TRUE) { | |
1980 | return KAL_TRUE; | |
1981 | } else { | |
1982 | battery_xlog_printk(BAT_LOG_CRTI, "[pmic_chrdet_status] No charger\r\n"); | |
1983 | return KAL_FALSE; | |
1984 | } | |
1985 | } | |
1986 | ||
1987 | /* ///////////////////////////////////////////////////////////////////////////////////////// */ | |
1988 | /* // Pulse Charging Algorithm */ | |
1989 | /* ///////////////////////////////////////////////////////////////////////////////////////// */ | |
1990 | kal_bool bat_is_charger_exist(void) | |
1991 | { | |
1992 | return get_charger_detect_status(); | |
1993 | } | |
1994 | ||
1995 | ||
1996 | kal_bool bat_is_charging_full(void) | |
1997 | { | |
1998 | if ((BMT_status.bat_full == KAL_TRUE) && (BMT_status.bat_in_recharging_state == KAL_FALSE)) | |
1999 | return KAL_TRUE; | |
2000 | else | |
2001 | return KAL_FALSE; | |
2002 | } | |
2003 | ||
2004 | ||
2005 | kal_uint32 bat_get_ui_percentage(void) | |
2006 | { | |
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; | |
2010 | else | |
2011 | return BMT_status.UI_SOC; | |
2012 | } | |
2013 | ||
2014 | /* Full state --> recharge voltage --> full state */ | |
2015 | kal_uint32 bat_is_recharging_phase(void) | |
2016 | { | |
2017 | return (BMT_status.bat_in_recharging_state || BMT_status.bat_full == KAL_TRUE); | |
2018 | } | |
2019 | ||
2020 | ||
2021 | int get_bat_charging_current_level(void) | |
2022 | { | |
2023 | CHR_CURRENT_ENUM charging_current; | |
2024 | ||
2025 | battery_charging_control(CHARGING_CMD_GET_CURRENT, &charging_current); | |
2026 | ||
2027 | return charging_current; | |
2028 | } | |
2029 | ||
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; | |
2033 | #endif | |
2034 | /* [PLATFORM]-Add-END by TCTSZ.leo.guo */ | |
2035 | ||
2036 | #if defined(MTK_TEMPERATURE_RECHARGE_SUPPORT) | |
2037 | PMU_STATUS do_batt_temp_state_machine(void) | |
2038 | { | |
2039 | if (BMT_status.temperature == ERR_CHARGE_TEMPERATURE) { | |
2040 | return PMU_STATUS_FAIL; | |
2041 | } | |
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) { | |
2047 | #else | |
2048 | if (BMT_status.temperature < MIN_CHARGE_TEMPERATURE) { | |
2049 | #endif | |
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; | |
2064 | } else { | |
2065 | return PMU_STATUS_FAIL; | |
2066 | } | |
2067 | } else | |
2068 | #endif | |
2069 | ||
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))){ | |
2075 | #else | |
2076 | if (BMT_status.temperature >= MAX_CHARGE_TEMPERATURE) { | |
2077 | #endif | |
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; | |
2089 | #else | |
2090 | if (BMT_status.temperature < MAX_CHARGE_TEMPERATURE_MINUS_X_DEGREE) { | |
2091 | #endif | |
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; | |
2100 | } else { | |
2101 | return PMU_STATUS_FAIL; | |
2102 | } | |
2103 | } else { | |
2104 | g_batt_temp_status = TEMP_POS_NORMAL; | |
2105 | } | |
2106 | return PMU_STATUS_OK; | |
2107 | } | |
2108 | #endif | |
2109 | ||
2110 | unsigned long BAT_Get_Battery_Voltage(int polling_mode) | |
2111 | { | |
2112 | unsigned long ret_val = 0; | |
2113 | ||
2114 | #if defined(CONFIG_POWER_EXT) | |
2115 | ret_val = 4000; | |
2116 | #else | |
2117 | ret_val=battery_meter_get_battery_voltage(KAL_FALSE); | |
2118 | #endif | |
2119 | ||
2120 | return ret_val; | |
2121 | } | |
2122 | ||
2123 | ||
2124 | static void mt_battery_average_method_init(kal_uint32 *bufferdata, kal_uint32 data, | |
2125 | kal_int32 *sum) | |
2126 | { | |
2127 | kal_uint32 i; | |
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; | |
2132 | ||
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) { | |
2140 | #else | |
2141 | if ((BMT_status.charger_type == STANDARD_CHARGER) || | |
2142 | (DISO_data.diso_state.cur_vdc_state == DISO_ONLINE)) { | |
2143 | #endif | |
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 */ | |
2149 | else /* USB */ | |
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) { | |
2156 | #else | |
2157 | if ((BMT_status.charger_type == STANDARD_CHARGER) || | |
2158 | (DISO_data.diso_state.cur_vdc_state == DISO_ONLINE)) { | |
2159 | #endif | |
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 */ | |
2165 | else /* USB */ | |
2166 | data = USB_CHARGER_CURRENT / 100; /* mA */ | |
2167 | } | |
2168 | ||
2169 | previous_in_recharge_state = BMT_status.bat_in_recharging_state; | |
2170 | } else { | |
2171 | if (previous_charger_exist == KAL_TRUE) { | |
2172 | batteryBufferFirst = KAL_TRUE; | |
2173 | previous_charger_exist = KAL_FALSE; | |
2174 | data = 0; | |
2175 | } | |
2176 | } | |
2177 | /* reset charging current window while plug in/out } */ | |
2178 | ||
2179 | battery_xlog_printk(BAT_LOG_FULL, "batteryBufferFirst =%d, data= (%d)\n", | |
2180 | batteryBufferFirst, data); | |
2181 | ||
2182 | if (batteryBufferFirst == KAL_TRUE) { | |
2183 | for (i = 0; i < BATTERY_AVERAGE_SIZE; i++) { | |
2184 | bufferdata[i] = data; | |
2185 | } | |
2186 | ||
2187 | *sum = data * BATTERY_AVERAGE_SIZE; | |
2188 | } | |
2189 | ||
2190 | index++; | |
2191 | if (index >= BATTERY_AVERAGE_DATA_NUMBER) { | |
2192 | index = BATTERY_AVERAGE_DATA_NUMBER; | |
2193 | batteryBufferFirst = KAL_FALSE; | |
2194 | } | |
2195 | } | |
2196 | ||
2197 | ||
2198 | static kal_uint32 mt_battery_average_method(kal_uint32 *bufferdata, kal_uint32 data, | |
2199 | kal_int32 *sum, kal_uint8 batteryIndex) | |
2200 | { | |
2201 | kal_uint32 avgdata; | |
2202 | ||
2203 | mt_battery_average_method_init(bufferdata, data, sum); | |
2204 | ||
2205 | *sum -= bufferdata[batteryIndex]; | |
2206 | *sum += data; | |
2207 | bufferdata[batteryIndex] = data; | |
2208 | avgdata = (*sum) / BATTERY_AVERAGE_SIZE; | |
2209 | ||
2210 | battery_xlog_printk(BAT_LOG_FULL, "bufferdata[%d]= (%d)\n", batteryIndex, | |
2211 | bufferdata[batteryIndex]); | |
2212 | return avgdata; | |
2213 | } | |
2214 | ||
2215 | void mt_battery_GetBatteryData(void) | |
2216 | { | |
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; | |
2225 | ||
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(); | |
2230 | } else { | |
2231 | ICharging = 0; | |
2232 | } | |
2233 | ||
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); | |
2238 | ||
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(); | |
2243 | ||
2244 | bat_meter_timeout = KAL_FALSE; | |
2245 | bat_spm_timeout = FALSE; | |
2246 | } else { | |
2247 | if (previous_SOC == -1) | |
2248 | SOC = battery_meter_get_battery_percentage(); | |
2249 | else | |
2250 | SOC = previous_SOC; | |
2251 | } | |
2252 | ||
2253 | ZCV = battery_meter_get_battery_zcv(); | |
2254 | ||
2255 | BMT_status.ICharging = | |
2256 | mt_battery_average_method(&batteryCurrentBuffer[0], ICharging, &icharging_sum, | |
2257 | batteryIndex); | |
2258 | ||
2259 | ||
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, | |
2265 | batteryIndex); | |
2266 | } else { | |
2267 | BMT_status.bat_vol = | |
2268 | mt_battery_average_method(&batteryVoltageBuffer[0], bat_vol, &bat_sum, | |
2269 | batteryIndex); | |
2270 | } | |
2271 | BMT_status.temperature = | |
2272 | mt_battery_average_method(&batteryTempBuffer[0], temperature, &temperature_sum, | |
2273 | batteryIndex); | |
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; | |
2280 | ||
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; | |
2284 | #endif | |
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; | |
2289 | } | |
2290 | ||
2291 | previous_SOC = BMT_status.SOC; | |
2292 | ||
2293 | batteryIndex++; | |
2294 | if (batteryIndex >= BATTERY_AVERAGE_SIZE) | |
2295 | batteryIndex = 0; | |
2296 | ||
2297 | ||
2298 | if (g_battery_soc_ready == KAL_FALSE) | |
2299 | g_battery_soc_ready = KAL_TRUE; | |
2300 | ||
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); | |
2306 | ||
2307 | ||
2308 | } | |
2309 | ||
2310 | ||
2311 | static PMU_STATUS mt_battery_CheckBatteryTemp(void) | |
2312 | { | |
2313 | PMU_STATUS status = PMU_STATUS_OK; | |
2314 | ||
2315 | #if defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT) | |
2316 | ||
2317 | battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] support JEITA, temperature=%d\n", | |
2318 | BMT_status.temperature); | |
2319 | ||
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; | |
2323 | } | |
2324 | #else | |
2325 | ||
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; | |
2330 | } | |
2331 | #else | |
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; | |
2338 | } | |
2339 | #endif | |
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; | |
2343 | } | |
2344 | #endif | |
2345 | ||
2346 | #endif | |
2347 | ||
2348 | return status; | |
2349 | } | |
2350 | ||
2351 | ||
2352 | static PMU_STATUS mt_battery_CheckChargerVoltage(void) | |
2353 | { | |
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; | |
2357 | #endif | |
2358 | ||
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; | |
2365 | } | |
2366 | #endif | |
2367 | #if !defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT) | |
2368 | if (BMT_status.charger_vol >= V_CHARGER_MAX) { | |
2369 | #else | |
2370 | if (BMT_status.charger_vol >= v_charger_max) { | |
2371 | #endif | |
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; | |
2376 | } | |
2377 | } | |
2378 | ||
2379 | return status; | |
2380 | } | |
2381 | ||
2382 | ||
2383 | static PMU_STATUS mt_battery_CheckChargingTime(void) | |
2384 | { | |
2385 | PMU_STATUS status = PMU_STATUS_OK; | |
2386 | ||
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); | |
2393 | ||
2394 | } else { | |
2395 | /* Charging OT */ | |
2396 | if (BMT_status.total_charging_time >= MAX_CHARGING_TIME) { | |
2397 | battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] Charging Over Time.\n"); | |
2398 | ||
2399 | status = PMU_STATUS_FAIL; | |
2400 | } | |
2401 | } | |
2402 | ||
2403 | return status; | |
2404 | ||
2405 | } | |
2406 | ||
2407 | #if defined(STOP_CHARGING_IN_TAKLING) | |
2408 | static PMU_STATUS mt_battery_CheckCallState(void) | |
2409 | { | |
2410 | PMU_STATUS status = PMU_STATUS_OK; | |
2411 | ||
2412 | if ((g_call_state == CALL_ACTIVE) && (BMT_status.bat_vol > V_CC2TOPOFF_THRES)) | |
2413 | status = PMU_STATUS_FAIL; | |
2414 | ||
2415 | return status; | |
2416 | } | |
2417 | #endif | |
2418 | ||
2419 | static void mt_battery_CheckBatteryStatus(void) | |
2420 | { | |
2421 | battery_xlog_printk(BAT_LOG_FULL, "[mt_battery_CheckBatteryStatus] cmd_discharging=(%d)\n", | |
2422 | cmd_discharging); | |
2423 | if (cmd_discharging == 1) { | |
2424 | battery_xlog_printk(BAT_LOG_CRTI, | |
2425 | "[mt_battery_CheckBatteryStatus] cmd_discharging=(%d)\n", | |
2426 | cmd_discharging); | |
2427 | BMT_status.bat_charging_state = CHR_ERROR; | |
2428 | battery_charging_control(CHARGING_CMD_SET_ERROR_STATE, &cmd_discharging); | |
2429 | return; | |
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; | |
2434 | } | |
2435 | if (mt_battery_CheckBatteryTemp() != PMU_STATUS_OK) { | |
2436 | BMT_status.bat_charging_state = CHR_ERROR; | |
2437 | return; | |
2438 | } | |
4b9e9796 | 2439 | |
6fa3eb70 S |
2440 | if (mt_battery_CheckChargerVoltage() != PMU_STATUS_OK) { |
2441 | BMT_status.bat_charging_state = CHR_ERROR; | |
2442 | return; | |
2443 | } | |
2444 | #if defined(STOP_CHARGING_IN_TAKLING) | |
2445 | if (mt_battery_CheckCallState() != PMU_STATUS_OK) { | |
2446 | BMT_status.bat_charging_state = CHR_HOLD; | |
2447 | return; | |
2448 | } | |
2449 | #endif | |
2450 | ||
2451 | if (mt_battery_CheckChargingTime() != PMU_STATUS_OK) { | |
2452 | BMT_status.bat_charging_state = CHR_ERROR; | |
2453 | return; | |
2454 | } | |
2455 | } | |
2456 | ||
2457 | ||
2458 | static void mt_battery_notify_TotalChargingTime_check(void) | |
2459 | { | |
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"); | |
2464 | } else { | |
2465 | if (BMT_status.total_charging_time >= MAX_CHARGING_TIME) | |
2466 | /* if(BMT_status.total_charging_time >= 60) //test */ | |
2467 | { | |
2468 | g_BatteryNotifyCode |= 0x0010; | |
2469 | battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] Charging Over Time\n"); | |
2470 | } else { | |
2471 | g_BatteryNotifyCode &= ~(0x0010); | |
2472 | } | |
2473 | } | |
2474 | ||
2475 | battery_xlog_printk(BAT_LOG_CRTI, | |
2476 | "[BATTERY] BATTERY_NOTIFY_CASE_0005_TOTAL_CHARGINGTIME (%x)\n", | |
2477 | g_BatteryNotifyCode); | |
2478 | #endif | |
2479 | } | |
2480 | ||
2481 | ||
2482 | static void mt_battery_notify_VBat_check(void) | |
2483 | { | |
2484 | #if defined(BATTERY_NOTIFY_CASE_0004_VBAT) | |
2485 | if (BMT_status.bat_vol > 4350) | |
2486 | /* if(BMT_status.bat_vol > 3800) //test */ | |
2487 | { | |
2488 | g_BatteryNotifyCode |= 0x0008; | |
2489 | battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] bat_vlot(%ld) > 4350mV\n", | |
2490 | BMT_status.bat_vol); | |
2491 | } else { | |
2492 | g_BatteryNotifyCode &= ~(0x0008); | |
2493 | } | |
2494 | ||
2495 | battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] BATTERY_NOTIFY_CASE_0004_VBAT (%x)\n", | |
2496 | g_BatteryNotifyCode); | |
2497 | ||
2498 | #endif | |
2499 | } | |
2500 | ||
2501 | ||
2502 | static void mt_battery_notify_ICharging_check(void) | |
2503 | { | |
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); | |
2509 | } else { | |
2510 | g_BatteryNotifyCode &= ~(0x0004); | |
2511 | } | |
2512 | ||
2513 | battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] BATTERY_NOTIFY_CASE_0003_ICHARGING (%x)\n", | |
2514 | g_BatteryNotifyCode); | |
2515 | ||
2516 | #endif | |
2517 | } | |
2518 | ||
2519 | ||
2520 | static void mt_battery_notify_VBatTemp_check(void) | |
2521 | { | |
2522 | #if defined(BATTERY_NOTIFY_CASE_0002_VBATTEMP) | |
2523 | ||
2524 | if (BMT_status.temperature >= MAX_CHARGE_TEMPERATURE) { | |
4b9e9796 | 2525 | /* [PLATFORM]-ADD-BEGIN by TCTSZ leo.guo, 06/09/2015, BATTERY Notify PR-1018754*/ |
6fa3eb70 | 2526 | if(BMT_status.temperature >= MAX_RAISING_CHARGE_TEMPERATURE) |
4b9e9796 | 2527 | g_BatteryNotifyCode |= (0x0040 | (!!BMT_status.charger_exist) << 8); |
6fa3eb70 | 2528 | else |
4b9e9796 S |
2529 | g_BatteryNotifyCode |= (0x0002 | (!!BMT_status.charger_exist) << 8); |
2530 | /* [PLATFORM]-ADD-END by TCTSZ leo.guo*/ | |
6fa3eb70 S |
2531 | battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] bat_temp(%d) out of range(too high)\n", |
2532 | BMT_status.temperature); | |
2533 | } | |
2534 | #if defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT) | |
2535 | else if (BMT_status.temperature < TEMP_NEG_10_THRESHOLD) { | |
4b9e9796 | 2536 | /* [PLATFORM]-ADD-BEGIN by TCTSZ leo.guo, 06/09/2015, BATTERY Notify PR-1018754*/ |
6fa3eb70 | 2537 | if(BMT_status.temperature <= MIN_DROPPING_CHARGE_TEMPERATURE) |
4b9e9796 | 2538 | g_BatteryNotifyCode |= (0x0080 | (!!BMT_status.charger_exist) << 8); |
6fa3eb70 | 2539 | else |
4b9e9796 S |
2540 | g_BatteryNotifyCode |= (0x0020 | (!!BMT_status.charger_exist) << 8); |
2541 | /* [PLATFORM]-ADD-END by TCTSZ leo.guo*/ | |
6fa3eb70 S |
2542 | battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] bat_temp(%d) out of range(too low)\n", |
2543 | BMT_status.temperature); | |
2544 | } | |
2545 | #else | |
2546 | #ifdef BAT_LOW_TEMP_PROTECT_ENABLE | |
2547 | else if (BMT_status.temperature < MIN_CHARGE_TEMPERATURE) { | |
4b9e9796 | 2548 | /* [PLATFORM]-ADD-BEGIN by TCTSZ leo.guo, 06/09/2015, BATTERY Notify PR-1018754*/ |
6fa3eb70 | 2549 | if(BMT_status.temperature <= MIN_DROPPING_CHARGE_TEMPERATURE) |
4b9e9796 | 2550 | g_BatteryNotifyCode |= (0x0080 | (!!BMT_status.charger_exist) << 8); |
6fa3eb70 | 2551 | else |
4b9e9796 S |
2552 | g_BatteryNotifyCode |= (0x0020 | (!!BMT_status.charger_exist) << 8); |
2553 | /* [PLATFORM]-ADD-END by TCTSZ leo.guo*/ | |
6fa3eb70 S |
2554 | battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] bat_temp(%d) out of range(too low)\n", |
2555 | BMT_status.temperature); | |
2556 | } | |
2557 | #endif | |
2558 | #endif | |
2559 | ||
2560 | battery_xlog_printk(BAT_LOG_FULL, "[BATTERY] BATTERY_NOTIFY_CASE_0002_VBATTEMP (%x)\n", | |
2561 | g_BatteryNotifyCode); | |
2562 | ||
2563 | #endif | |
2564 | } | |
2565 | ||
2566 | ||
2567 | static void mt_battery_notify_VCharger_check(void) | |
2568 | { | |
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; | |
2572 | #endif | |
2573 | ||
2574 | #if !defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT) | |
2575 | if (BMT_status.charger_vol > V_CHARGER_MAX) { | |
2576 | #else | |
2577 | if (BMT_status.charger_vol > v_charger_max) { | |
2578 | #endif | |
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); | |
2582 | } else { | |
2583 | g_BatteryNotifyCode &= ~(0x0001); | |
2584 | } | |
2585 | if (g_BatteryNotifyCode != 0x0000) | |
2586 | battery_xlog_printk(BAT_LOG_CRTI, | |
2587 | "[BATTERY] BATTERY_NOTIFY_CASE_0001_VCHARGER (%x)\n", | |
2588 | g_BatteryNotifyCode); | |
2589 | #endif | |
2590 | } | |
2591 | ||
2592 | ||
2593 | static void mt_battery_notify_UI_test(void) | |
2594 | { | |
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"); | |
2615 | } else { | |
2616 | battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] Unknown BN_TestMode Code : %x\n", | |
2617 | g_BN_TestMode); | |
2618 | } | |
2619 | } | |
2620 | ||
2621 | ||
2622 | void mt_battery_notify_check(void) | |
2623 | { | |
2624 | g_BatteryNotifyCode = 0x0000; | |
2625 | ||
2626 | if (g_BN_TestMode == 0x0000) { /* for normal case */ | |
2627 | battery_xlog_printk(BAT_LOG_FULL, "[BATTERY] mt_battery_notify_check\n"); | |
2628 | ||
2629 | mt_battery_notify_VCharger_check(); | |
2630 | ||
2631 | mt_battery_notify_VBatTemp_check(); | |
2632 | ||
2633 | mt_battery_notify_ICharging_check(); | |
2634 | ||
2635 | mt_battery_notify_VBat_check(); | |
2636 | ||
2637 | mt_battery_notify_TotalChargingTime_check(); | |
2638 | } else { /* for UI test */ | |
2639 | ||
2640 | mt_battery_notify_UI_test(); | |
2641 | } | |
2642 | } | |
2643 | ||
2644 | static void mt_battery_thermal_check(void) | |
2645 | { | |
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); | |
2652 | } | |
2653 | #if defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT) | |
2654 | /* ignore default rule */ | |
2655 | #else | |
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"); | |
2660 | #else | |
2661 | { | |
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); | |
2668 | } else { | |
2669 | struct battery_data *bat_data = &battery_main; | |
2670 | struct power_supply *bat_psy = &bat_data->psy; | |
2671 | ||
2672 | battery_xlog_printk(BAT_LOG_CRTI, | |
2673 | "[Battery] Tbat(%d)>=60 or <=-20 , system need power down.\n", | |
2674 | BMT_status.temperature); | |
2675 | ||
2676 | bat_data->BAT_CAPACITY = 0; | |
2677 | ||
2678 | power_supply_changed(bat_psy); | |
2679 | ||
2680 | if (BMT_status.charger_exist == KAL_TRUE) { | |
2681 | /* can not power down due to charger exist, so need reset system */ | |
6fa3eb70 S |
2682 | battery_charging_control |
2683 | (CHARGING_CMD_SET_PLATFORM_RESET, NULL); | |
6fa3eb70 S |
2684 | } |
2685 | /* avoid SW no feedback */ | |
4b9e9796 | 2686 | battery_charging_control(CHARGING_CMD_SET_POWER_OFF, NULL); |
6fa3eb70 | 2687 | /* mt_power_off(); */ |
6fa3eb70 S |
2688 | } |
2689 | } | |
2690 | #endif | |
2691 | } | |
2692 | #endif | |
2693 | ||
2694 | } | |
2695 | ||
2696 | } | |
2697 | ||
2698 | ||
2699 | static void mt_battery_update_status(void) | |
2700 | { | |
2701 | #if defined(CONFIG_POWER_EXT) | |
2702 | battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] CONFIG_POWER_EXT, no update Android.\n"); | |
2703 | #else | |
2704 | { | |
2705 | wireless_update(&wireless_main); | |
2706 | battery_update(&battery_main); | |
2707 | ac_update(&ac_main); | |
2708 | usb_update(&usb_main); | |
2709 | } | |
2710 | ||
2711 | #endif | |
2712 | } | |
2713 | ||
2714 | ||
2715 | CHARGER_TYPE mt_charger_type_detection(void) | |
2716 | { | |
2717 | CHARGER_TYPE CHR_Type_num = CHARGER_UNKNOWN; | |
2718 | ||
2719 | mutex_lock(&charger_type_mutex); | |
2720 | ||
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; | |
2724 | #else | |
2725 | #if !defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT) | |
2726 | if (BMT_status.charger_type == CHARGER_UNKNOWN) { | |
2727 | #else | |
2728 | if ((BMT_status.charger_type == CHARGER_UNKNOWN) && | |
2729 | (DISO_data.diso_state.cur_vusb_state == DISO_ONLINE)) { | |
2730 | #endif | |
2731 | battery_charging_control(CHARGING_CMD_GET_CHARGER_TYPE, &CHR_Type_num); | |
2732 | BMT_status.charger_type = CHR_Type_num; | |
2733 | ||
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) | |
2736 | { | |
2737 | BMT_status.bat_charging_state = CHR_BATFULL; | |
2738 | BMT_status.bat_full = KAL_TRUE; | |
2739 | g_charging_full_reset_bat_meter = KAL_TRUE; | |
2740 | } | |
2741 | ||
2742 | if(g_battery_soc_ready == KAL_FALSE) { | |
2743 | if(BMT_status.nPercent_ZCV == 0) | |
2744 | battery_meter_initial(); | |
2745 | ||
2746 | BMT_status.SOC = battery_meter_get_battery_percentage(); | |
2747 | } | |
2748 | ||
2749 | if (BMT_status.bat_vol > 0) | |
2750 | { | |
2751 | mt_battery_update_status(); | |
2752 | } | |
2753 | ||
2754 | #endif | |
2755 | } | |
2756 | #endif | |
2757 | mutex_unlock(&charger_type_mutex); | |
2758 | ||
2759 | return BMT_status.charger_type; | |
2760 | } | |
2761 | ||
2762 | CHARGER_TYPE mt_get_charger_type(void) | |
2763 | { | |
2764 | #if defined(CONFIG_POWER_EXT) || defined(CONFIG_MTK_FPGA) | |
2765 | return STANDARD_HOST; | |
2766 | #else | |
2767 | return BMT_status.charger_type; | |
2768 | #endif | |
2769 | } | |
2770 | ||
2771 | static void mt_battery_charger_detect_check(void) | |
2772 | { | |
2773 | if (upmu_is_chr_det() == KAL_TRUE) { | |
2774 | wake_lock(&battery_suspend_lock); | |
2775 | ||
2776 | #if !defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT) | |
2777 | BMT_status.charger_exist = KAL_TRUE; | |
2778 | #endif | |
2779 | ||
2780 | #if defined(CONFIG_MTK_WIRELESS_CHARGER_SUPPORT) | |
2781 | mt_charger_type_detection(); | |
2782 | ||
2783 | if ((BMT_status.charger_type == STANDARD_HOST) | |
2784 | || (BMT_status.charger_type == CHARGING_HOST)) { | |
2785 | mt_usb_connect(); | |
2786 | } | |
2787 | #else | |
2788 | #if !defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT) | |
2789 | if (BMT_status.charger_type == CHARGER_UNKNOWN) { | |
2790 | #else | |
2791 | if ((BMT_status.charger_type == CHARGER_UNKNOWN) && | |
2792 | (DISO_data.diso_state.cur_vusb_state == DISO_ONLINE)) { | |
2793 | #endif | |
2794 | mt_charger_type_detection(); | |
2795 | ||
2796 | if ((BMT_status.charger_type == STANDARD_HOST) | |
2797 | || (BMT_status.charger_type == CHARGING_HOST)) { | |
2798 | mt_usb_connect(); | |
2799 | } | |
2800 | } | |
2801 | #endif | |
2802 | ||
2803 | battery_xlog_printk(BAT_LOG_CRTI, "[BAT_thread]Cable in, CHR_Type_num=%d\r\n", | |
2804 | BMT_status.charger_type); | |
2805 | ||
2806 | } else { | |
2807 | wake_unlock(&battery_suspend_lock); | |
2808 | ||
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; | |
2819 | ||
2820 | battery_xlog_printk(BAT_LOG_CRTI, "[BAT_thread]Cable out \r\n"); | |
2821 | ||
2822 | mt_usb_disconnect(); | |
2823 | } | |
2824 | } | |
2825 | ||
2826 | static void mt_kpoc_power_off_check(void) | |
2827 | { | |
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 */ | |
2835 | { | |
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); | |
2839 | } | |
2840 | } | |
2841 | #endif | |
2842 | } | |
2843 | ||
2844 | void update_battery_2nd_info(int status_smb, int capacity_smb, int present_smb) | |
2845 | { | |
2846 | #if defined(CONFIG_POWER_VERIFY) | |
2847 | battery_xlog_printk(BAT_LOG_CRTI, "[update_battery_smb_info] no support\n"); | |
2848 | #else | |
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); | |
2855 | ||
2856 | wake_up_bat(); | |
2857 | g_smartbook_update = 1; | |
2858 | #endif | |
2859 | } | |
2860 | ||
2861 | void do_chrdet_int_task(void) | |
2862 | { | |
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) { | |
2866 | #else | |
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)) { | |
2870 | #endif | |
2871 | battery_xlog_printk(BAT_LOG_CRTI, "[do_chrdet_int_task] charger exist!\n"); | |
2872 | BMT_status.charger_exist = KAL_TRUE; | |
2873 | ||
2874 | wake_lock(&battery_suspend_lock); | |
2875 | ||
2876 | #if defined(CONFIG_POWER_EXT) | |
2877 | mt_usb_connect(); | |
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()) { | |
2882 | mt_usb_connect(); | |
2883 | battery_xlog_printk(BAT_LOG_CRTI, | |
2884 | "[do_chrdet_int_task] call mt_usb_connect() in EVB\n"); | |
2885 | return; | |
2886 | } | |
2887 | #endif | |
2888 | } else { | |
2889 | battery_xlog_printk(BAT_LOG_CRTI, | |
2890 | "[do_chrdet_int_task] charger NOT exist!\n"); | |
2891 | BMT_status.charger_exist = KAL_FALSE; | |
2892 | ||
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); | |
2897 | #endif | |
2898 | ||
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(); */ | |
2906 | } | |
2907 | #endif | |
2908 | ||
2909 | wake_unlock(&battery_suspend_lock); | |
2910 | ||
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"); | |
2920 | return; | |
2921 | } | |
2922 | #endif | |
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; | |
2927 | #endif | |
2928 | ||
2929 | } | |
2930 | ||
2931 | /* Place charger detection and battery update here is used to speed up charging icon display. */ | |
2932 | ||
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; | |
2938 | } | |
2939 | ||
2940 | if (g_battery_soc_ready == KAL_FALSE) { | |
2941 | if (BMT_status.nPercent_ZCV == 0) | |
2942 | battery_meter_initial(); | |
2943 | ||
2944 | BMT_status.SOC = battery_meter_get_battery_percentage(); | |
2945 | } | |
2946 | ||
2947 | if (BMT_status.bat_vol > 0) { | |
2948 | mt_battery_update_status(); | |
2949 | } | |
2950 | ||
2951 | #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT) | |
2952 | DISO_data.chr_get_diso_state = KAL_TRUE; | |
2953 | #endif | |
2954 | ||
2955 | wake_up_bat(); | |
2956 | } else { | |
2957 | #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT) | |
2958 | g_vcdt_irq_delay_flag = KAL_TRUE; | |
2959 | #endif | |
2960 | battery_xlog_printk(BAT_LOG_CRTI, | |
2961 | "[do_chrdet_int_task] battery thread not ready, will do after bettery init.\n"); | |
2962 | } | |
2963 | ||
2964 | } | |
2965 | ||
2966 | ||
2967 | void BAT_thread(void) | |
2968 | { | |
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; | |
2974 | ||
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 */ | |
2978 | ||
2979 | } | |
4b9e9796 | 2980 | |
6fa3eb70 S |
2981 | mt_battery_charger_detect_check(); |
2982 | mt_battery_GetBatteryData(); | |
2983 | if (BMT_status.charger_exist == KAL_TRUE) { | |
2984 | check_battery_exist(); | |
2985 | } | |
2986 | mt_battery_thermal_check(); | |
2987 | mt_battery_notify_check(); | |
2988 | ||
2989 | if (BMT_status.charger_exist == KAL_TRUE) { | |
2990 | mt_battery_CheckBatteryStatus(); | |
2991 | mt_battery_charging_algorithm(); | |
2992 | } | |
2993 | ||
2994 | mt_battery_update_status(); | |
2995 | mt_kpoc_power_off_check(); | |
2996 | } | |
2997 | ||
2998 | /* ///////////////////////////////////////////////////////////////////////////////////////// */ | |
2999 | /* // Internal API */ | |
3000 | /* ///////////////////////////////////////////////////////////////////////////////////////// */ | |
4b9e9796 S |
3001 | |
3002 | #ifdef BATTERY_CDP_WORKAROUND | |
3003 | extern kal_bool is_charger_detection_rdy(void); | |
3004 | #endif | |
3005 | ||
6fa3eb70 S |
3006 | int bat_thread_kthread(void *x) |
3007 | { | |
3008 | ktime_t ktime = ktime_set(3, 0); /* 10s, 10* 1000 ms */ | |
3009 | ||
4b9e9796 S |
3010 | |
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"); | |
3016 | }else{ | |
3017 | printk("xiaohu_cdp:CDP, PASS\n"); | |
3018 | } | |
3019 | #endif | |
3020 | ||
3021 | ||
6fa3eb70 S |
3022 | /* Run on a process content */ |
3023 | while (1) { | |
3024 | mutex_lock(&bat_mutex); | |
3025 | ||
3026 | if ((chargin_hw_init_done == KAL_TRUE) && (battery_suspended == KAL_FALSE)) | |
3027 | BAT_thread(); | |
3028 | ||
3029 | mutex_unlock(&bat_mutex); | |
3030 | ||
3031 | battery_xlog_printk(BAT_LOG_FULL, "wait event \n" ); | |
3032 | ||
3033 | wait_event(bat_thread_wq, (bat_thread_timeout == KAL_TRUE)); | |
3034 | ||
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 */ | |
3039 | { | |
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); | |
3044 | } | |
3045 | #endif | |
3046 | ||
3047 | g_smartbook_update = 0; | |
3048 | #if defined(CUST_CAPACITY_OCV2CV_TRANSFORM) | |
3049 | battery_meter_set_reset_soc(KAL_FALSE); | |
3050 | #endif | |
3051 | battery_meter_reset(); | |
3052 | chr_wake_up_bat = KAL_FALSE; | |
3053 | ||
3054 | battery_xlog_printk(BAT_LOG_CRTI, | |
3055 | "[BATTERY] Charger plug in/out, Call battery_meter_reset. (%d)\n", | |
3056 | BMT_status.UI_SOC); | |
3057 | } | |
3058 | ||
3059 | } | |
3060 | ||
3061 | return 0; | |
3062 | } | |
3063 | ||
3064 | void bat_thread_wakeup(void) | |
3065 | { | |
3066 | battery_xlog_printk(BAT_LOG_FULL, "******** battery : bat_thread_wakeup ********\n"); | |
3067 | ||
3068 | bat_thread_timeout = KAL_TRUE; | |
3069 | bat_meter_timeout = KAL_TRUE; | |
3070 | #ifdef MTK_ENABLE_AGING_ALGORITHM | |
3071 | suspend_time = 0; | |
3072 | #endif | |
3073 | _g_bat_sleep_total_time = 0; | |
3074 | wake_up(&bat_thread_wq); | |
3075 | } | |
3076 | ||
3077 | /* ///////////////////////////////////////////////////////////////////////////////////////// */ | |
3078 | /* // fop API */ | |
3079 | /* ///////////////////////////////////////////////////////////////////////////////////////// */ | |
3080 | static long adc_cali_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
3081 | { | |
3082 | int *user_data_addr; | |
3083 | int *naram_data_addr; | |
3084 | int i = 0; | |
3085 | int ret = 0; | |
3086 | int adc_in_data[2] = { 1, 1 }; | |
3087 | int adc_out_data[2] = { 1, 1 }; | |
3088 | ||
3089 | mutex_lock(&bat_mutex); | |
3090 | ||
3091 | switch (cmd) { | |
3092 | case TEST_ADC_CALI_PRINT: | |
3093 | g_ADC_Cali = KAL_FALSE; | |
3094 | break; | |
3095 | ||
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 */ | |
3100 | /* Protection */ | |
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; | |
3104 | } | |
3105 | } | |
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"); | |
3111 | break; | |
3112 | ||
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"); | |
3122 | break; | |
3123 | ||
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; | |
3130 | } else { | |
3131 | g_ADC_Cali = KAL_FALSE; | |
3132 | } | |
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"); | |
3137 | break; | |
3138 | ||
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 */ | |
3143 | ||
3144 | if (adc_in_data[0] == 0) /* I_SENSE */ | |
3145 | { | |
3146 | adc_out_data[0] = battery_meter_get_VSense() * adc_in_data[1]; | |
3147 | } else if (adc_in_data[0] == 1) /* BAT_SENSE */ | |
3148 | { | |
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 */ | |
3151 | { | |
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 */ | |
3155 | { | |
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; | |
3159 | ||
3160 | if (battery_meter_get_battery_current_sign() == KAL_TRUE) { | |
3161 | adc_out_data[0] = 0 - adc_out_data[0]; /* charging */ | |
3162 | } | |
3163 | } else { | |
3164 | battery_xlog_printk(BAT_LOG_FULL, "unknown channel(%d,%d)\n", | |
3165 | adc_in_data[0], adc_in_data[1]); | |
3166 | } | |
3167 | ||
3168 | if (adc_out_data[0] < 0) | |
3169 | adc_out_data[1] = 1; /* failed */ | |
3170 | else | |
3171 | adc_out_data[1] = 0; /* success */ | |
3172 | ||
3173 | if (adc_in_data[0] == 30) | |
3174 | adc_out_data[1] = 0; /* success */ | |
3175 | ||
3176 | if (adc_in_data[0] == 66) | |
3177 | adc_out_data[1] = 0; /* success */ | |
3178 | ||
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]); | |
3183 | break; | |
3184 | ||
3185 | case BAT_STATUS_READ: | |
3186 | user_data_addr = (int *)arg; | |
3187 | ret = copy_from_user(battery_in_data, user_data_addr, 4); | |
3188 | /* [0] is_CAL */ | |
3189 | if (g_ADC_Cali) { | |
3190 | battery_out_data[0] = 1; | |
3191 | } else { | |
3192 | battery_out_data[0] = 0; | |
3193 | } | |
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]); | |
3197 | break; | |
3198 | ||
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; | |
3235 | } else { | |
3236 | charging_level_data[0] = CHARGE_CURRENT_450_00_MA; | |
3237 | } | |
3238 | wake_up_bat(); | |
3239 | battery_xlog_printk(BAT_LOG_CRTI, "**** unlocked_ioctl : set_Charger_Current:%d\n", | |
3240 | charging_level_data[0]); | |
3241 | break; | |
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); | |
3248 | ||
3249 | break; | |
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); | |
3255 | ||
3256 | break; | |
3257 | /* add bing meta tool------------------------------- */ | |
3258 | ||
3259 | default : | |
3260 | g_ADC_Cali = KAL_FALSE; | |
3261 | break; | |
3262 | } | |
3263 | ||
3264 | mutex_unlock(&bat_mutex); | |
3265 | ||
3266 | return 0; | |
3267 | } | |
3268 | ||
3269 | static int adc_cali_open(struct inode *inode, struct file *file) | |
3270 | { | |
3271 | return 0; | |
3272 | } | |
3273 | ||
3274 | static int adc_cali_release(struct inode *inode, struct file *file) | |
3275 | { | |
3276 | return 0; | |
3277 | } | |
3278 | ||
3279 | ||
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, | |
3285 | }; | |
3286 | ||
3287 | ||
3288 | void check_battery_exist(void) | |
3289 | { | |
3290 | #if defined(CONFIG_DIS_CHECK_BATTERY) | |
3291 | battery_xlog_printk(BAT_LOG_CRTI, "[BATTERY] Disable check battery exist.\n"); | |
3292 | #else | |
3293 | kal_uint32 baton_count = 0; | |
3294 | kal_uint32 charging_enable = KAL_FALSE; | |
3295 | kal_uint32 battery_status; | |
3296 | kal_uint32 i; | |
3297 | ||
3298 | for (i = 0; i < 3; i++) { | |
3299 | battery_charging_control(CHARGING_CMD_GET_BATTERY_STATUS, &battery_status); | |
3300 | baton_count += battery_status; | |
3301 | ||
3302 | } | |
3303 | ||
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); | |
3310 | } else { | |
3311 | battery_xlog_printk(BAT_LOG_CRTI, | |
3312 | "[BATTERY] Battery is not exist, power off FAN5405 and system (%d)\n", | |
3313 | baton_count); | |
3314 | ||
3315 | battery_charging_control(CHARGING_CMD_ENABLE, &charging_enable); | |
3316 | battery_charging_control(CHARGING_CMD_SET_POWER_OFF, NULL); | |
3317 | } | |
3318 | } | |
3319 | #endif | |
3320 | } | |
3321 | ||
3322 | ||
3323 | int charger_hv_detect_sw_thread_handler(void *unused) | |
3324 | { | |
3325 | ktime_t ktime; | |
3326 | kal_uint32 charging_enable; | |
3327 | kal_uint32 hv_voltage = V_CHARGER_MAX*1000; | |
3328 | kal_bool hv_status; | |
3329 | ||
3330 | #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT) | |
3331 | hv_voltage = DISO_data.hv_voltage; | |
3332 | #endif | |
3333 | ||
3334 | do { | |
3335 | ktime = ktime_set(0, BAT_MS_TO_NS(1000)); | |
3336 | ||
3337 | if (chargin_hw_init_done) | |
3338 | battery_charging_control(CHARGING_CMD_SET_HV_THRESHOLD, &hv_voltage); | |
3339 | ||
3340 | wait_event_interruptible(charger_hv_detect_waiter, | |
3341 | (charger_hv_detect_flag == KAL_TRUE)); | |
3342 | ||
3343 | if ((upmu_is_chr_det() == KAL_TRUE)) { | |
3344 | check_battery_exist(); | |
3345 | } | |
3346 | ||
3347 | charger_hv_detect_flag = KAL_FALSE; | |
3348 | ||
3349 | if (chargin_hw_init_done) | |
3350 | battery_charging_control(CHARGING_CMD_GET_HV_STATUS, &hv_status); | |
3351 | ||
3352 | if (hv_status == KAL_TRUE) { | |
3353 | battery_xlog_printk(BAT_LOG_CRTI, | |
3354 | "[charger_hv_detect_sw_thread_handler] charger hv\n"); | |
3355 | ||
3356 | charging_enable = KAL_FALSE; | |
3357 | if (chargin_hw_init_done) | |
3358 | battery_charging_control(CHARGING_CMD_ENABLE, &charging_enable); | |
3359 | } else { | |
3360 | battery_xlog_printk(BAT_LOG_FULL, | |
3361 | "[charger_hv_detect_sw_thread_handler] upmu_chr_get_vcdt_hv_det() != 1\n"); | |
3362 | } | |
3363 | ||
3364 | if (chargin_hw_init_done) | |
3365 | battery_charging_control(CHARGING_CMD_RESET_WATCH_DOG_TIMER, NULL); | |
3366 | ||
3367 | hrtimer_start(&charger_hv_detect_timer, ktime, HRTIMER_MODE_REL); | |
3368 | ||
3369 | } while (!kthread_should_stop()); | |
3370 | ||
3371 | return 0; | |
3372 | } | |
3373 | ||
3374 | enum hrtimer_restart charger_hv_detect_sw_workaround(struct hrtimer *timer) | |
3375 | { | |
3376 | charger_hv_detect_flag = KAL_TRUE; | |
3377 | wake_up_interruptible(&charger_hv_detect_waiter); | |
3378 | ||
3379 | battery_xlog_printk(BAT_LOG_FULL, "[charger_hv_detect_sw_workaround]\n"); | |
3380 | ||
3381 | return HRTIMER_NORESTART; | |
3382 | } | |
3383 | ||
3384 | void charger_hv_detect_sw_workaround_init(void) | |
3385 | { | |
3386 | ktime_t ktime; | |
3387 | ||
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); | |
3392 | ||
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", | |
3399 | __func__); | |
3400 | } | |
3401 | check_battery_exist(); | |
3402 | battery_xlog_printk(BAT_LOG_CRTI, "charger_hv_detect_sw_workaround_init : done\n"); | |
3403 | } | |
3404 | ||
3405 | ||
3406 | enum hrtimer_restart battery_kthread_hrtimer_func(struct hrtimer *timer) | |
3407 | { | |
3408 | bat_thread_wakeup(); | |
3409 | ||
3410 | return HRTIMER_NORESTART; | |
3411 | } | |
3412 | ||
3413 | void battery_kthread_hrtimer_init(void) | |
3414 | { | |
3415 | ktime_t ktime; | |
3416 | ||
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); | |
3421 | ||
3422 | battery_xlog_printk(BAT_LOG_CRTI, "battery_kthread_hrtimer_init : done\n"); | |
3423 | } | |
3424 | ||
3425 | ||
3426 | static void get_charging_control(void) | |
3427 | { | |
3428 | battery_charging_control = chr_control_interface; | |
3429 | } | |
3430 | ||
3431 | #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT) | |
3432 | static irqreturn_t diso_auxadc_irq_thread(int irq, void *dev_id) | |
3433 | { | |
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; | |
3437 | ||
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]); | |
3441 | ||
3442 | switch (pre_diso_state) { | |
3443 | #ifdef MTK_DISCRETE_SWITCH /*for DSC DC plugin handle */ | |
3444 | case USB_ONLY: | |
3445 | #endif | |
3446 | case OTG_ONLY: | |
3447 | BMT_status.charger_exist = KAL_TRUE; | |
3448 | wake_lock(&battery_suspend_lock); | |
3449 | wake_up_bat(); | |
3450 | break; | |
3451 | case DC_WITH_OTG: | |
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); | |
3457 | wake_up_bat(); | |
3458 | break; | |
3459 | case DC_WITH_USB: | |
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 | |
3464 | wake_up_bat(); | |
3465 | break; | |
3466 | case DC_ONLY: | |
3467 | BMT_status.charger_type = CHARGER_UNKNOWN; | |
3468 | mt_battery_charger_detect_check(); //plug in VUSB, check if need connect usb | |
3469 | break; | |
3470 | default: | |
3471 | battery_xlog_printk(BAT_LOG_CRTI, | |
3472 | "[DISO]VUSB auxadc threaded handler triggered ERROR OR TEST\n"); | |
3473 | break; | |
3474 | } | |
3475 | return IRQ_HANDLED; | |
3476 | } | |
3477 | ||
3478 | static void dual_input_init(void) | |
3479 | { | |
3480 | DISO_data.irq_callback_func = diso_auxadc_irq_thread; | |
3481 | battery_charging_control(CHARGING_CMD_DISO_INIT, &DISO_data); | |
3482 | } | |
3483 | #endif | |
3484 | static int battery_probe(struct platform_device *dev) | |
3485 | { | |
3486 | struct class_device *class_dev = NULL; | |
3487 | int ret = 0; | |
3488 | ||
3489 | battery_xlog_printk(BAT_LOG_CRTI, "******** battery driver probe!! ********\n"); | |
3490 | ||
3491 | /* Integrate with NVRAM */ | |
3492 | ret = alloc_chrdev_region(&adc_cali_devno, 0, 1, ADC_CALI_DEVNAME); | |
3493 | if (ret) | |
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); | |
3499 | if (ret) | |
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, | |
3504 | NULL, | |
3505 | adc_cali_devno, NULL, ADC_CALI_DEVNAME); | |
3506 | battery_xlog_printk(BAT_LOG_CRTI, "[BAT_probe] adc_cali prepare : done !!\n "); | |
3507 | ||
3508 | get_charging_control(); | |
3509 | ||
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); | |
3513 | ||
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"); | |
3517 | #endif | |
3518 | ||
3519 | /* Integrate with Android Battery Service */ | |
3520 | ret = power_supply_register(&(dev->dev), &ac_main.psy); | |
3521 | if (ret) { | |
3522 | battery_xlog_printk(BAT_LOG_CRTI, "[BAT_probe] power_supply_register AC Fail !!\n"); | |
3523 | return ret; | |
3524 | } | |
3525 | battery_xlog_printk(BAT_LOG_CRTI, "[BAT_probe] power_supply_register AC Success !!\n"); | |
3526 | ||
3527 | ret = power_supply_register(&(dev->dev), &usb_main.psy); | |
3528 | if (ret) { | |
3529 | battery_xlog_printk(BAT_LOG_CRTI, | |
3530 | "[BAT_probe] power_supply_register USB Fail !!\n"); | |
3531 | return ret; | |
3532 | } | |
3533 | battery_xlog_printk(BAT_LOG_CRTI, "[BAT_probe] power_supply_register USB Success !!\n"); | |
3534 | ||
3535 | ret = power_supply_register(&(dev->dev), &wireless_main.psy); | |
3536 | if (ret) { | |
3537 | battery_xlog_printk(BAT_LOG_CRTI, | |
3538 | "[BAT_probe] power_supply_register WIRELESS Fail !!\n"); | |
3539 | return ret; | |
3540 | } | |
3541 | battery_xlog_printk(BAT_LOG_CRTI, | |
3542 | "[BAT_probe] power_supply_register WIRELESS Success !!\n"); | |
3543 | ||
3544 | ret = power_supply_register(&(dev->dev), &battery_main.psy); | |
3545 | if (ret) { | |
3546 | battery_xlog_printk(BAT_LOG_CRTI, | |
3547 | "[BAT_probe] power_supply_register Battery Fail !!\n"); | |
3548 | return ret; | |
3549 | } | |
3550 | battery_xlog_printk(BAT_LOG_CRTI, "[BAT_probe] power_supply_register Battery Success !!\n"); | |
3551 | ||
3552 | #if !defined(CONFIG_POWER_EXT) | |
3553 | ||
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; | |
3563 | ||
3564 | g_bat_init_flag = KAL_TRUE; | |
3565 | return 0; | |
3566 | } | |
3567 | #endif | |
3568 | /* For EM */ | |
3569 | { | |
3570 | int ret_device_file = 0; | |
3571 | ||
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); | |
3575 | #endif | |
3576 | /* [PLATFORM]-Add-END by TCTSZ.leo.guo */ | |
3577 | ret_device_file = device_create_file(&(dev->dev), &dev_attr_ADC_Charger_Voltage); | |
3578 | ||
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); | |
3593 | ||
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); | |
3608 | ||
3609 | ret_device_file = | |
3610 | device_create_file(&(dev->dev), &dev_attr_ADC_Channel_Is_Calibration); | |
3611 | ||
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); | |
3615 | ||
3616 | ret_device_file = | |
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); | |
3623 | #endif | |
3624 | } | |
3625 | ||
3626 | /* battery_meter_initial(); //move to mt_battery_GetBatteryData() to decrease booting time */ | |
3627 | ||
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; | |
3640 | BMT_status.SOC = 0; | |
3641 | #ifdef CUST_CAPACITY_OCV2CV_TRANSFORM | |
3642 | BMT_status.UI_SOC = -1; | |
3643 | #else | |
3644 | BMT_status.UI_SOC = 0; | |
3645 | #endif | |
3646 | ||
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(); | |
3652 | ||
3653 | #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT) | |
3654 | dual_input_init(); | |
3655 | #endif | |
3656 | ||
3657 | /* battery kernel thread for 10s check and charger in/out event */ | |
3658 | /* Replace GPT timer by hrtime */ | |
3659 | battery_kthread_hrtimer_init(); | |
3660 | ||
3661 | kthread_run(bat_thread_kthread, NULL, "bat_thread_kthread"); | |
3662 | battery_xlog_printk(BAT_LOG_CRTI, "[battery_probe] bat_thread_kthread Done\n"); | |
3663 | ||
3664 | charger_hv_detect_sw_workaround_init(); | |
3665 | ||
3666 | /*LOG System Set */ | |
3667 | init_proc_log(); | |
3668 | ||
3669 | #else | |
3670 | //keep HW alive | |
3671 | charger_hv_detect_sw_workaround_init(); | |
3672 | #endif | |
3673 | g_bat_init_flag = KAL_TRUE; | |
3674 | ||
3675 | #if defined(CONFIG_MTK_DUAL_INPUT_CHARGER_SUPPORT) | |
3676 | if (g_vcdt_irq_delay_flag == KAL_TRUE) | |
3677 | do_chrdet_int_task(); | |
3678 | #endif | |
3679 | ||
3680 | return 0; | |
3681 | ||
3682 | } | |
3683 | ||
3684 | static void battery_timer_pause(void) | |
3685 | { | |
3686 | struct timespec xts, tom; | |
3687 | ||
3688 | //battery_xlog_printk(BAT_LOG_CRTI, "******** battery driver suspend!! ********\n" ); | |
3689 | #ifdef CONFIG_POWER_EXT | |
3690 | #else | |
3691 | ||
3692 | #ifdef CONFIG_MTK_POWER_EXT_DETECT | |
3693 | if (KAL_TRUE == bat_is_ext_power()) | |
3694 | return 0; | |
3695 | #endif | |
3696 | mutex_lock(&bat_mutex); | |
3697 | //cancel timer | |
3698 | hrtimer_cancel(&battery_kthread_timer); | |
3699 | hrtimer_cancel(&charger_hv_detect_timer); | |
3700 | ||
3701 | battery_suspended = KAL_TRUE; | |
3702 | mutex_unlock(&bat_mutex); | |
3703 | ||
3704 | battery_xlog_printk(BAT_LOG_CRTI, "@bs=1@\n" ); | |
3705 | #endif | |
3706 | ||
3707 | get_xtime_and_monotonic_and_sleep_offset(&xts, &tom, &g_bat_time_before_sleep); | |
3708 | } | |
3709 | ||
3710 | static void battery_timer_resume(void) | |
3711 | { | |
3712 | #ifdef CONFIG_POWER_EXT | |
3713 | #else | |
3714 | kal_bool is_pcm_timer_trigger = KAL_FALSE; | |
3715 | struct timespec xts, tom, bat_time_after_sleep; | |
3716 | ktime_t ktime, hvtime; | |
3717 | ||
3718 | #ifdef CONFIG_MTK_POWER_EXT_DETECT | |
3719 | if (KAL_TRUE == bat_is_ext_power()) | |
3720 | return 0; | |
3721 | #endif | |
3722 | ||
3723 | ktime = ktime_set(BAT_TASK_PERIOD, 0); // 10s, 10* 1000 ms | |
3724 | hvtime = ktime_set(0, BAT_MS_TO_NS(2000)); | |
3725 | ||
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); | |
3728 | ||
3729 | if(is_pcm_timer_trigger == KAL_TRUE || bat_spm_timeout) | |
3730 | { | |
3731 | mutex_lock(&bat_mutex); | |
3732 | BAT_thread(); | |
3733 | mutex_unlock(&bat_mutex); | |
3734 | } | |
3735 | else | |
3736 | { | |
3737 | battery_xlog_printk(BAT_LOG_CRTI, "battery resume NOT by pcm timer!!\n" ); | |
3738 | } | |
3739 | ||
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 | |
3741 | { | |
3742 | BMT_status.UI_SOC = battery_meter_get_battery_percentage(); | |
3743 | battery_xlog_printk(BAT_LOG_CRTI, "Sync UI SOC to SOC immediately\n" ); | |
3744 | } | |
3745 | ||
3746 | mutex_lock(&bat_mutex); | |
3747 | ||
3748 | //restore timer | |
3749 | hrtimer_start(&battery_kthread_timer, ktime, HRTIMER_MODE_REL); | |
3750 | hrtimer_start(&charger_hv_detect_timer, hvtime, HRTIMER_MODE_REL); | |
3751 | ||
3752 | battery_suspended = KAL_FALSE; | |
3753 | battery_xlog_printk(BAT_LOG_CRTI, "@bs=0@\n"); | |
3754 | mutex_unlock(&bat_mutex); | |
3755 | ||
3756 | #endif | |
3757 | } | |
3758 | ||
3759 | static int battery_remove(struct platform_device *dev) | |
3760 | { | |
3761 | battery_xlog_printk(BAT_LOG_CRTI, "******** battery driver remove!! ********\n"); | |
3762 | ||
3763 | return 0; | |
3764 | } | |
3765 | ||
3766 | static void battery_shutdown(struct platform_device *dev) | |
3767 | { | |
3768 | battery_xlog_printk(BAT_LOG_CRTI, "******** battery driver shutdown!! ********\n"); | |
3769 | ||
3770 | } | |
3771 | ||
3772 | /* ///////////////////////////////////////////////////////////////////////////////////////// */ | |
3773 | /* // Battery Notify API */ | |
3774 | /* ///////////////////////////////////////////////////////////////////////////////////////// */ | |
3775 | static ssize_t show_BatteryNotify(struct device *dev, struct device_attribute *attr, char *buf) | |
3776 | { | |
3777 | battery_xlog_printk(BAT_LOG_CRTI, "[Battery] show_BatteryNotify : %x\n", | |
3778 | g_BatteryNotifyCode); | |
3779 | ||
3780 | return sprintf(buf, "%u\n", g_BatteryNotifyCode); | |
3781 | } | |
3782 | ||
3783 | static ssize_t store_BatteryNotify(struct device *dev, struct device_attribute *attr, | |
3784 | const char *buf, size_t size) | |
3785 | { | |
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, | |
3791 | size); | |
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); | |
3796 | } | |
3797 | return size; | |
3798 | } | |
3799 | ||
3800 | static DEVICE_ATTR(BatteryNotify, 0664, show_BatteryNotify, store_BatteryNotify); | |
3801 | ||
3802 | static ssize_t show_BN_TestMode(struct device *dev, struct device_attribute *attr, char *buf) | |
3803 | { | |
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); | |
3806 | } | |
3807 | ||
3808 | static ssize_t store_BN_TestMode(struct device *dev, struct device_attribute *attr, const char *buf, | |
3809 | size_t size) | |
3810 | { | |
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, | |
3816 | size); | |
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", | |
3820 | g_BN_TestMode); | |
3821 | } | |
3822 | return size; | |
3823 | } | |
3824 | ||
3825 | static DEVICE_ATTR(BN_TestMode, 0664, show_BN_TestMode, store_BN_TestMode); | |
3826 | ||
3827 | ||
3828 | /* ///////////////////////////////////////////////////////////////////////////////////////// */ | |
3829 | /* // platform_driver API */ | |
3830 | /* ///////////////////////////////////////////////////////////////////////////////////////// */ | |
3831 | #if 0 | |
3832 | static int battery_cmd_read(char *buf, char **start, off_t off, int count, int *eof, void *data) | |
3833 | { | |
3834 | int len = 0; | |
3835 | char *p = buf; | |
3836 | ||
3837 | p += sprintf(p, | |
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); | |
3841 | ||
3842 | *start = buf + off; | |
3843 | ||
3844 | len = p - buf; | |
3845 | if (len > off) | |
3846 | len -= off; | |
3847 | else | |
3848 | len = 0; | |
3849 | ||
3850 | return len < count ? len : count; | |
3851 | } | |
3852 | #endif | |
3853 | ||
3854 | static ssize_t battery_cmd_write(struct file *file, const char *buffer, size_t count, loff_t *data) | |
3855 | { | |
3856 | int len = 0, bat_tt_enable = 0, bat_thr_test_mode = 0, bat_thr_test_value = 0; | |
3857 | char desc[32]; | |
3858 | ||
3859 | len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1); | |
3860 | if (copy_from_user(desc, buffer, len)) { | |
3861 | return 0; | |
3862 | } | |
3863 | desc[len] = '\0'; | |
3864 | ||
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; | |
3869 | ||
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); | |
3875 | ||
3876 | return count; | |
3877 | } else { | |
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"); | |
3880 | } | |
3881 | ||
3882 | return -EINVAL; | |
3883 | } | |
3884 | ||
3885 | static int proc_utilization_show(struct seq_file *m, void *v) | |
3886 | { | |
3887 | seq_printf(m, | |
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); | |
3891 | ||
3892 | seq_printf(m, "=> get_usb_current_unlimited=%d,\ncmd_discharging = %d\n", | |
3893 | get_usb_current_unlimited(), cmd_discharging); | |
3894 | return 0; | |
3895 | } | |
3896 | ||
3897 | static int proc_utilization_open(struct inode *inode, struct file *file) | |
3898 | { | |
3899 | return single_open(file, proc_utilization_show, NULL); | |
3900 | } | |
3901 | ||
3902 | static const struct file_operations battery_cmd_proc_fops = { | |
3903 | .open = proc_utilization_open, | |
3904 | .read = seq_read, | |
3905 | .write = battery_cmd_write, | |
3906 | }; | |
3907 | ||
3908 | static ssize_t current_cmd_write(struct file *file, const char *buffer, size_t count, loff_t *data) | |
3909 | { | |
3910 | int len = 0; | |
3911 | char desc[32]; | |
3912 | int cmd_current_unlimited = false; | |
3913 | U32 charging_enable = false; | |
3914 | ||
3915 | len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1); | |
3916 | if (copy_from_user(desc, buffer, len)) { | |
3917 | return 0; | |
3918 | } | |
3919 | desc[len] = '\0'; | |
3920 | ||
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; | |
3925 | adjust_power = -1; | |
3926 | } else if (cmd_discharging == 0) { | |
3927 | charging_enable = true; | |
3928 | adjust_power = -1; | |
3929 | } | |
3930 | battery_charging_control(CHARGING_CMD_ENABLE, &charging_enable); | |
3931 | ||
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); | |
3935 | return count; | |
3936 | } else { | |
3937 | battery_xlog_printk(BAT_LOG_CRTI, " bad argument, echo [enable] > current_cmd\n"); | |
3938 | } | |
3939 | ||
3940 | return -EINVAL; | |
3941 | } | |
3942 | ||
3943 | static int current_cmd_read(struct seq_file *m, void *v) | |
3944 | { | |
3945 | U32 charging_enable = false; | |
3946 | ||
3947 | cmd_discharging = 1; | |
3948 | charging_enable = false; | |
3949 | adjust_power = -1; | |
3950 | ||
3951 | battery_charging_control(CHARGING_CMD_ENABLE, &charging_enable); | |
3952 | ||
3953 | battery_xlog_printk(BAT_LOG_CRTI, | |
3954 | "[current_cmd_write] cmd_discharging=%d\n", cmd_discharging); | |
3955 | ||
3956 | return 0; | |
3957 | } | |
3958 | ||
3959 | static int proc_utilization_open_cur_stop(struct inode *inode, struct file *file) | |
3960 | { | |
3961 | return single_open(file, current_cmd_read, NULL); | |
3962 | } | |
3963 | static ssize_t discharging_cmd_write(struct file *file, const char *buffer, size_t count, loff_t *data) | |
3964 | { | |
3965 | int len = 0; | |
3966 | char desc[32]; | |
3967 | U32 charging_enable = false; | |
3968 | ||
3969 | len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1); | |
3970 | if (copy_from_user(desc, buffer, len)) { | |
3971 | return 0; | |
3972 | } | |
3973 | desc[len] = '\0'; | |
3974 | ||
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); | |
3977 | return count; | |
3978 | } else { | |
3979 | battery_xlog_printk(BAT_LOG_CRTI, " bad argument, echo [enable] > current_cmd\n"); | |
3980 | } | |
3981 | ||
3982 | return -EINVAL; | |
3983 | } | |
3984 | ||
3985 | static const struct file_operations discharging_cmd_proc_fops = { | |
3986 | .open = proc_utilization_open, | |
3987 | .read = seq_read, | |
3988 | .write = discharging_cmd_write, | |
3989 | }; | |
3990 | ||
3991 | static const struct file_operations current_cmd_proc_fops = { | |
3992 | .open = proc_utilization_open_cur_stop, | |
3993 | .read = seq_read, | |
3994 | .write = current_cmd_write, | |
3995 | }; | |
3996 | ||
3997 | static int mt_batteryNotify_probe(struct platform_device *dev) | |
3998 | { | |
3999 | int ret_device_file = 0; | |
4000 | /* struct proc_dir_entry *entry = NULL; */ | |
4001 | struct proc_dir_entry *battery_dir = NULL; | |
4002 | ||
4003 | battery_xlog_printk(BAT_LOG_CRTI, "******** mt_batteryNotify_probe!! ********\n"); | |
4004 | ||
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); | |
4007 | ||
4008 | battery_dir = proc_mkdir("mtk_battery_cmd", NULL); | |
4009 | if (!battery_dir) { | |
4010 | pr_err("[%s]: mkdir /proc/mtk_battery_cmd failed\n", __func__); | |
4011 | } else { | |
4012 | #if 1 | |
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"); | |
4015 | ||
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"); | |
4020 | ||
4021 | ||
4022 | #else | |
4023 | entry = create_proc_entry("battery_cmd", S_IRUGO | S_IWUSR, battery_dir); | |
4024 | if (entry) { | |
4025 | entry->read_proc = battery_cmd_read; | |
4026 | entry->write_proc = battery_cmd_write; | |
4027 | } | |
4028 | #endif | |
4029 | } | |
4030 | ||
4031 | battery_xlog_printk(BAT_LOG_CRTI, "******** mtk_battery_cmd!! ********\n"); | |
4032 | ||
4033 | return 0; | |
4034 | ||
4035 | } | |
4036 | #ifdef CONFIG_OF | |
4037 | static const struct of_device_id mt_battery_of_match[] = { | |
4038 | { .compatible = "mediatek,battery", }, | |
4039 | {}, | |
4040 | }; | |
4041 | ||
4042 | MODULE_DEVICE_TABLE(of, mt_battery_of_match); | |
4043 | #endif | |
4044 | ||
4045 | static int battery_pm_suspend(struct device *device) | |
4046 | { | |
4047 | int ret = 0; | |
4048 | struct platform_device *pdev = to_platform_device(device); | |
4049 | BUG_ON(pdev == NULL); | |
4050 | ||
4051 | return ret; | |
4052 | } | |
4053 | ||
4054 | static int battery_pm_resume(struct device *device) | |
4055 | { | |
4056 | int ret = 0; | |
4057 | struct platform_device *pdev = to_platform_device(device); | |
4058 | BUG_ON(pdev == NULL); | |
4059 | ||
4060 | return ret; | |
4061 | } | |
4062 | ||
4063 | static int battery_pm_freeze(struct device *device) | |
4064 | { | |
4065 | int ret = 0; | |
4066 | struct platform_device *pdev = to_platform_device(device); | |
4067 | BUG_ON(pdev == NULL); | |
4068 | ||
4069 | return ret; | |
4070 | } | |
4071 | ||
4072 | static int battery_pm_restore(struct device *device) | |
4073 | { | |
4074 | int ret = 0; | |
4075 | struct platform_device *pdev = to_platform_device(device); | |
4076 | BUG_ON(pdev == NULL); | |
4077 | ||
4078 | return ret; | |
4079 | } | |
4080 | ||
4081 | static int battery_pm_restore_noirq(struct device *device) | |
4082 | { | |
4083 | int ret = 0; | |
4084 | struct platform_device *pdev = to_platform_device(device); | |
4085 | BUG_ON(pdev == NULL); | |
4086 | ||
4087 | return ret; | |
4088 | } | |
4089 | ||
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, | |
4097 | }; | |
4098 | ||
4099 | #if defined(CONFIG_OF) || defined(BATTERY_MODULE_INIT) | |
4100 | struct platform_device battery_device = { | |
4101 | .name = "battery", | |
4102 | .id = -1, | |
4103 | }; | |
4104 | #endif | |
4105 | ||
4106 | static struct platform_driver battery_driver = { | |
4107 | .probe = battery_probe, | |
4108 | .remove = battery_remove, | |
4109 | .shutdown = battery_shutdown, | |
4110 | .driver = { | |
4111 | .name = "battery", | |
4112 | .pm = &battery_pm_ops, | |
4113 | }, | |
4114 | }; | |
4115 | ||
4116 | #ifdef CONFIG_OF | |
4117 | static int battery_dts_probe(struct platform_device *dev) | |
4118 | { | |
4119 | int ret = 0; | |
4120 | /* struct proc_dir_entry *entry = NULL; */ | |
4121 | struct proc_dir_entry *battery_dir = NULL; | |
4122 | ||
4123 | battery_xlog_printk(BAT_LOG_CRTI, "******** battery_dts_probe!! ********\n"); | |
4124 | ||
4125 | battery_device.dev.of_node = dev->dev.of_node; | |
4126 | ret = platform_device_register(&battery_device); | |
4127 | if (ret) { | |
4128 | battery_xlog_printk(BAT_LOG_CRTI, | |
4129 | "****[battery_dts_probe] Unable to register device (%d)\n", ret); | |
4130 | return ret; | |
4131 | } | |
4132 | return 0; | |
4133 | ||
4134 | } | |
4135 | ||
4136 | static struct platform_driver battery_dts_driver = { | |
4137 | .probe = battery_dts_probe, | |
4138 | .remove = NULL, | |
4139 | .shutdown = NULL, | |
4140 | .driver = { | |
4141 | .name = "battery-dts", | |
4142 | #ifdef CONFIG_OF | |
4143 | .of_match_table = mt_battery_of_match, | |
4144 | #endif | |
4145 | }, | |
4146 | }; | |
4147 | ||
4148 | //-------------------------------------------------------- | |
4149 | ||
4150 | static const struct of_device_id mt_bat_notify_of_match[] = { | |
4151 | { .compatible = "mediatek,bat_notify", }, | |
4152 | {}, | |
4153 | }; | |
4154 | ||
4155 | MODULE_DEVICE_TABLE(of, mt_bat_notify_of_match); | |
4156 | #endif | |
4157 | ||
4158 | struct platform_device MT_batteryNotify_device = { | |
4159 | .name = "mt-battery", | |
4160 | .id = -1, | |
4161 | }; | |
4162 | ||
4163 | static struct platform_driver mt_batteryNotify_driver = { | |
4164 | .probe = mt_batteryNotify_probe, | |
4165 | .driver = { | |
4166 | .name = "mt-battery", | |
4167 | }, | |
4168 | }; | |
4169 | ||
4170 | #ifdef CONFIG_OF | |
4171 | static int mt_batteryNotify_dts_probe(struct platform_device *dev) | |
4172 | { | |
4173 | int ret = 0; | |
4174 | /* struct proc_dir_entry *entry = NULL; */ | |
4175 | struct proc_dir_entry *battery_dir = NULL; | |
4176 | ||
4177 | battery_xlog_printk(BAT_LOG_CRTI, "******** mt_batteryNotify_dts_probe!! ********\n"); | |
4178 | ||
4179 | MT_batteryNotify_device.dev.of_node = dev->dev.of_node; | |
4180 | ret = platform_device_register(&MT_batteryNotify_device); | |
4181 | if (ret) { | |
4182 | battery_xlog_printk(BAT_LOG_CRTI, | |
4183 | "****[mt_batteryNotify_dts] Unable to register device (%d)\n", ret); | |
4184 | return ret; | |
4185 | } | |
4186 | return 0; | |
4187 | ||
4188 | } | |
4189 | ||
4190 | ||
4191 | static struct platform_driver mt_batteryNotify_dts_driver = { | |
4192 | .probe = mt_batteryNotify_dts_probe, | |
4193 | .driver = { | |
4194 | .name = "mt-dts-battery", | |
4195 | #ifdef CONFIG_OF | |
4196 | .of_match_table = mt_bat_notify_of_match, | |
4197 | #endif | |
4198 | }, | |
4199 | }; | |
4200 | #endif | |
4201 | //-------------------------------------------------------- | |
4202 | ||
4203 | static int battery_pm_event(struct notifier_block *notifier, unsigned long pm_event, void *unused) | |
4204 | { | |
4205 | switch(pm_event) { | |
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(); | |
4211 | return NOTIFY_DONE; | |
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(); | |
4217 | return NOTIFY_DONE; | |
4218 | } | |
4219 | return NOTIFY_OK; | |
4220 | } | |
4221 | ||
4222 | static struct notifier_block battery_pm_notifier_block = { | |
4223 | .notifier_call = battery_pm_event, | |
4224 | .priority = 0, | |
4225 | }; | |
4226 | ||
4227 | static int __init battery_init(void) | |
4228 | { | |
4229 | int ret; | |
4230 | ||
4231 | printk("battery_init\n"); | |
4232 | ||
4233 | #ifdef CONFIG_OF | |
4234 | // | |
4235 | #else | |
4236 | ||
4237 | #ifdef BATTERY_MODULE_INIT | |
4238 | ret = platform_device_register(&battery_device); | |
4239 | if (ret) { | |
4240 | battery_xlog_printk(BAT_LOG_CRTI, | |
4241 | "****[battery_device] Unable to device register(%d)\n", ret); | |
4242 | return ret; | |
4243 | } | |
4244 | #endif | |
4245 | #endif | |
4246 | ||
4247 | ret = platform_driver_register(&battery_driver); | |
4248 | if (ret) { | |
4249 | battery_xlog_printk(BAT_LOG_CRTI, | |
4250 | "****[battery_driver] Unable to register driver (%d)\n", ret); | |
4251 | return ret; | |
4252 | } | |
4253 | /* battery notofy UI */ | |
4254 | #ifdef CONFIG_OF | |
4255 | // | |
4256 | #else | |
4257 | ret = platform_device_register(&MT_batteryNotify_device); | |
4258 | if (ret) { | |
4259 | battery_xlog_printk(BAT_LOG_CRTI, | |
4260 | "****[mt_batteryNotify] Unable to device register(%d)\n", ret); | |
4261 | return ret; | |
4262 | } | |
4263 | #endif | |
4264 | ret = platform_driver_register(&mt_batteryNotify_driver); | |
4265 | if (ret) { | |
4266 | battery_xlog_printk(BAT_LOG_CRTI, | |
4267 | "****[mt_batteryNotify] Unable to register driver (%d)\n", ret); | |
4268 | return ret; | |
4269 | } | |
4270 | #ifdef CONFIG_OF | |
4271 | ret = platform_driver_register(&battery_dts_driver); | |
4272 | ret = platform_driver_register(&mt_batteryNotify_dts_driver); | |
4273 | #endif | |
4274 | ret = register_pm_notifier(&battery_pm_notifier_block); | |
4275 | if (ret) | |
4276 | printk("[%s] failed to register PM notifier %d\n", __func__, ret); | |
4277 | ||
4278 | battery_xlog_printk(BAT_LOG_CRTI, "****[battery_driver] Initialization : DONE !!\n"); | |
4279 | return 0; | |
4280 | } | |
4281 | ||
4282 | #ifdef BATTERY_MODULE_INIT | |
4283 | late_initcall(battery_init); | |
4284 | #else | |
4285 | static void __exit battery_exit(void) | |
4286 | { | |
4287 | } | |
4288 | module_init(battery_init); | |
4289 | module_exit(battery_exit); | |
4290 | #endif | |
4291 | ||
4292 | MODULE_AUTHOR("Oscar Liu"); | |
4293 | MODULE_DESCRIPTION("Battery Device Driver"); | |
4294 | MODULE_LICENSE("GPL"); |