blob: df34a3f4fa3ed9a0940cabedd91966c3eb0f1bff [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001/*****************************************************************************
2* Copyright Statement:
3* --------------------
4* This software is protected by Copyright and the information contained
5* herein is confidential. The software may not be copied and the information
6* contained herein may not be used or disclosed except with the written
7* permission of MediaTek Inc. (C) 2005
8*
9* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
10* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
11* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
12* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
13* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
15* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
16* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
17* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
18* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
19* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
20* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
21*
22* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
23* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
24* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
25* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
26* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
27*
28* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
29* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
30* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
31* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
32* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
33*
34*****************************************************************************/
35
36/*****************************************************************************
37 *
38 * Filename:
39 * ---------
40 * bmt.h
41 *
42 * Project:
43 * --------
44 * Maui_Software
45 *
46 * Description:
47 * ------------
48 * This file is intends for Battery Management Task.
49 *
50 * Author:
51 * -------
52 * -------
53 *
54 *============================================================================
55 * HISTORY
56 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
57 *------------------------------------------------------------------------------
58 * removed!
59 * removed!
60 * removed!
61 *
62 * removed!
63 * removed!
64 * removed!
65 *
66 * removed!
67 * removed!
68 * removed!
69 *
70 * removed!
71 * removed!
72 * removed!
73 *
74 * removed!
75 * removed!
76 * removed!
77 *
78 * removed!
79 * removed!
80 * removed!
81 *
82 * removed!
83 * removed!
84 * removed!
85 *
86 * removed!
87 * removed!
88 * removed!
89 *
90 * removed!
91 * removed!
92 * removed!
93 *
94 * removed!
95 * removed!
96 * removed!
97 *
98 * removed!
99 * removed!
100 * removed!
101 *
102 * removed!
103 * removed!
104 * removed!
105 *
106 * removed!
107 * removed!
108 * removed!
109 *
110 * removed!
111 * removed!
112 * removed!
113 *
114 * removed!
115 * removed!
116 * removed!
117 *
118 * removed!
119 * removed!
120 * removed!
121 *
122 * removed!
123 * removed!
124 * removed!
125 * removed!
126 *
127 * removed!
128 * removed!
129 * removed!
130 *
131 * removed!
132 * removed!
133 * removed!
134 *
135 * removed!
136 * removed!
137 * removed!
138 *
139 * removed!
140 * removed!
141 * removed!
142 *
143 * removed!
144 * removed!
145 * removed!
146 *
147 * removed!
148 * removed!
149 * removed!
150 *
151 * removed!
152 * removed!
153 * removed!
154 *
155 * removed!
156 * removed!
157 * removed!
158 *
159 * removed!
160 * removed!
161 * removed!
162 *
163 * removed!
164 * removed!
165 * removed!
166 *
167 * removed!
168 * removed!
169 * removed!
170 *
171 * removed!
172 * removed!
173 * removed!
174 *
175 * removed!
176 * removed!
177 * removed!
178 *
179 * removed!
180 * removed!
181 * removed!
182 *
183 * removed!
184 * removed!
185 * removed!
186 *
187 * removed!
188 * removed!
189 * removed!
190 *
191 * removed!
192 * removed!
193 * removed!
194 *
195 * removed!
196 * removed!
197 * removed!
198 *
199 * removed!
200 * removed!
201 * removed!
202 *
203 * removed!
204 * removed!
205 * removed!
206 *
207 * removed!
208 * removed!
209 * removed!
210 *
211 * removed!
212 * removed!
213 * removed!
214 *
215 * removed!
216 * removed!
217 * removed!
218 *
219 * removed!
220 * removed!
221 * removed!
222 *
223 * removed!
224 * removed!
225 * removed!
226 *
227 * removed!
228 * removed!
229 * removed!
230 *
231 * removed!
232 * removed!
233 * removed!
234 *
235 * removed!
236 * removed!
237 * removed!
238 *
239 * removed!
240 * removed!
241 * removed!
242 *
243 * removed!
244 * removed!
245 * removed!
246 *
247 * removed!
248 * removed!
249 * removed!
250 *
251 * removed!
252 * removed!
253 * removed!
254 *
255 * removed!
256 * removed!
257 * removed!
258 *
259 * removed!
260 * removed!
261 * removed!
262 *
263 * removed!
264 * removed!
265 * removed!
266 *
267 * removed!
268 * removed!
269 * removed!
270 *
271 * removed!
272 * removed!
273 * removed!
274 *
275 * removed!
276 * removed!
277 * removed!
278 *
279 * removed!
280 * removed!
281 * removed!
282 *
283 * removed!
284 * removed!
285 * removed!
286 *
287 * removed!
288 * removed!
289 * removed!
290 * removed!
291 * removed!
292 * removed!
293 * removed!
294 * removed!
295 * removed!
296 * removed!
297 * removed!
298 * removed!
299 * removed!
300 * removed!
301 * removed!
302 * removed!
303 * removed!
304 * removed!
305 * removed!
306 * removed!
307 * removed!
308 * removed!
309 * removed!
310 * removed!
311 * removed!
312 * removed!
313 * removed!
314 * removed!
315 * removed!
316 * removed!
317 * removed!
318 * removed!
319 * removed!
320 * removed!
321 * removed!
322 * removed!
323 * removed!
324 * removed!
325 * removed!
326 * removed!
327 * removed!
328 * removed!
329 * removed!
330 * removed!
331 * removed!
332 * removed!
333 * removed!
334 * removed!
335 * removed!
336 * removed!
337 * removed!
338 * removed!
339 * removed!
340 * removed!
341 * removed!
342 * removed!
343 * removed!
344 * removed!
345 * removed!
346 * removed!
347 * removed!
348 * removed!
349 * removed!
350 * removed!
351 * removed!
352 * removed!
353 * removed!
354 * removed!
355 * removed!
356 * removed!
357 * removed!
358 * removed!
359 * removed!
360 * removed!
361 * removed!
362 * removed!
363 * removed!
364 * removed!
365 * removed!
366 * removed!
367 * removed!
368 * removed!
369 * removed!
370 * removed!
371 * removed!
372 * removed!
373 * removed!
374 * removed!
375 * removed!
376 * removed!
377 * removed!
378 * removed!
379 * removed!
380 * removed!
381 * removed!
382 * removed!
383 * removed!
384 * removed!
385 * removed!
386 * removed!
387 * removed!
388 * removed!
389 * removed!
390 * removed!
391 * removed!
392 * removed!
393 * removed!
394 * removed!
395 * removed!
396 * removed!
397 * removed!
398 * removed!
399 * removed!
400 * removed!
401 *
402 *------------------------------------------------------------------------------
403 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
404 *============================================================================
405 ****************************************************************************/
406#ifndef _BMT_H
407#define _BMT_H
408
409#include "kal_general_types.h"
410#include "kal_public_defs.h"
411#include "dcl.h"
412#include "adc_cali.h"
413
414#define ADC_BMT_VBAT 0
415#define ADC_BMT_VISENSE 1
416#define ADC_BMT_VBATTMP 2
417#define ADC_BMT_VCHARGER 3
418#define ADC_BMT_MAX_CHANNEL_TOTAL 4
419//#define BMT_MAX_CHANNEL_TOTAL ADC_BMT_MAX_CHANNEL_TOTAL // backward compatible
420
421/*
422#ifdef __BMT_CHECK_CHARGER__
423#define BMT_MAX_CHANNEL 4
424#else
425#define BMT_MAX_CHANNEL 3
426#endif
427*/
428#define BMT_ADC_VBAT 0
429#define BMT_ADC_VISENSE 1
430#define BMT_ADC_VBATTMP 2
431#define BMT_ADC_VCHARGER 3
432#define BMT_ADC_MAX_CHANNEL_TOTAL 4
433
434/*precharge threshold*/
435#define BMT_PRECHARGE_THRESHOLD 3300000
436
437#if defined(__TC01__)
438#define DRV_BMT_NONE_USB_POWER_ON /* use charging power on instead of USB power on*/
439#define __DRV_BMT_PRECHARGE_TO_FULL_DIRECTLY__
440#endif // #if defined(__TC01__)
441
442/*BatType*/
443#define LIBAT 0
444#define NIBAT 1
445
446/*extern charger state*/
447#define DETECTCHRIN 0x0
448#define DETECTCHROUT !DETECTCHRIN
449
450/*BMT Minor STATE. When Charger is plugged in, charge is enable or not?*/
451#define PMIC_CHARGEOFF 0 /*pmictrl_state*/
452#define PMIC_CHARGEON 1
453
454/*MS Mode*/
455#define idle_mode 0
456#define talk_mode 1
457#define swoff_mode 2
458
459
460#define BMT_HIGH_VCHG_THRESHOLD 100000
461
462#if defined(DRV_BMT_HIGH_VCHG_ADAPTIVE_CHARGE_CURRENT_SUPPORT)
463#define VCHG_VOL_LEVEL 7
464#define VCHG_PARAMTER_COUNT 3
465
466typedef struct{
467 kal_uint32 VCHG_HV_VTH;
468 kal_int32 HIGH_VCHG_TABLE[VCHG_VOL_LEVEL][VCHG_PARAMTER_COUNT];
469}bmt_customized_high_vchg_struct;
470
471extern kal_bool High_Vchg_Safety_Timer_Set;
472extern bmt_customized_high_vchg_struct *bmt_high_vchg_para;
473extern kal_uint32 bmt_total_charge_time;
474extern kal_bool bmt_safety_timer_config;
475extern kal_int32 Pre_VCharge_AVG;
476extern kal_int32 Cur_VCharge_MAX;
477extern bmt_customized_high_vchg_struct *bmt_get_customized_high_vchg_para(void);
478
479#endif // End of #if defined(DRV_BMT_HIGH_VCHG_ADAPTIVE_CHARGE_CURRENT_SUPPORT)
480
481typedef enum{
482 CHARGER_PRESENT,
483//#if defined(__CHINA_CHARGER_STANDARD__)
484 CHARGER_PRESENT_NON,
485//#endif
486 USB_PRESENT,
487 NO_PRESENT
488}charger_usb_present_enum;
489
490typedef enum{
491 BMT_AC_CHR,
492 BMT_USB_CHR
493}bmt_charger_type;
494
495typedef enum {
496 bmt_chr_in=0,
497 bmt_chr_out,
498 bmt_chr_uninit = 0xff
499}Charger_Status;
500
501typedef enum {
502 VBAT_UEM_CHR_OUT=0,
503 VBAT_UEM_CHR_OUT_FIRST=1,
504 VBAT_UEM_CHR_IN=2,
505 VBAT_UEM_CHR_IN_FISRT=3
506}VBAT_UEM_CHR_ENUM;
507
508typedef enum
509{
510 CHR_CURRENT_50=0,
511 CHR_CURRENT_90,
512 CHR_CURRENT_150,
513 CHR_CURRENT_225,
514 CHR_CURRENT_300,
515 CHR_CURRENT_450,
516 CHR_CURRENT_650,
517 CHR_CURRENT_800
518}pmic_charging_current;
519
520typedef struct {
521 kal_uint8 bat_state;
522 kal_uint8 pmictrl_state; /*pmic control on,off*/
523 kal_uint8 call_state; /*mobile state*/
524 // kal_uint8 PWRon;
525 kal_uint8 BatType;
526 kal_uint8 EINT2STATE;
527 kal_uint8 highfull;
528 VBAT_UEM_CHR_ENUM VBAT_UEM; // state of UEM VBAT measurement
529 kal_hisrid hisr;
530} BMTStruct;
531
532typedef struct {
533 kal_int32 VBAT;
534 kal_int32 ICHARGE;
535 kal_int32 BATTMP;
536 kal_int32 VCHARGER;
537 kal_int32 ISense_Offset;
538 //kal_uint8 BATTYPE;
539} BATPHYStruct;
540
541
542// For external charger mechanism integration
543
544// The enum is to indicate whether the charging factor is measured by HOST or Charger device
545typedef enum
546{
547 CHR_FACTOR_MEASURE_NONE = 0x00000000, // Both NOT support, TBD
548 CHR_FACTOR_MEASURE_BY_HOST = 0x00000001, // BIT00, HOST measure the specific charging factor
549 CHR_FACTOR_MEASURE_BY_CHARGER_DEV = 0x00000002 // BIT01, Charger device measure the specific charging factor
550
551}bmt_chr_fac_measure_support_enum;
552
553// The enum is to indicate whether the charging factor error check is done by HOST or charger device
554typedef enum
555{
556 BMT_CHR_FACTOR_CHECK_NONE = 0x00000000, // Both NOT support, TBD
557 BMT_CHR_FACTOR_CHECK_BY_HOST = 0x00000001, // BIT00, HOST perform charging factor error check
558 BMT_CHR_FACTOR_CHECK_BY_CHARGER_DEV = 0x00000002 // BIT01, Charger device perform charging facotr error check
559
560}bmt_chr_fac_check_support_enum;
561
562// The enum defines the charging factors that charging process need to check
563typedef enum
564{
565 BMT_CHR_FACTOR_VBAT, // Charging factor: VBAT
566 BMT_CHR_FACTOR_ISENSE, // Charging factor: VISENSE
567 BMT_CHR_FACTOR_BATTMP, // Charging factor: VBAT temperature
568 BMT_CHR_FACTOR_VCHARGER, // Charging factor: VCHARGER
569 BMT_CHR_FACTOR_CHARGER_OVP, // Charging factor: Charger OVP
570 BMT_CHR_FACTOR_CHARGE_FULL, // Charging factor: Charge full
571 BMT_CHR_FACTOR_UNDER_EXTREMETMP, // Charging factor: Extreme temperature
572 BMT_CHR_FACTOR_CHARGE_EXTREMETMP_FULL, // Charging factor: Charge full under extreme temperature
573 BMT_CHR_FACTOR_CHARGE_EXTREMETMP_RECHARGE, // Charging factor: Should recharge under extreme temperature
574 BMT_CHR_FACTOR_HOLD, // Charging factor: Charging hold
575 BMT_CHR_FACTOR_CHR_BATT_STATE, // Charging factor: charging state: PRE, FAST(CC), TOPOFF(CV), FULL ...
576
577 BMT_CHR_FACTOR_MAX
578}bmt_chr_fac_enum;
579
580typedef struct
581{
582
583 // Driver init
584 // Called at drv init phase
585 void (*drv_init)(void);
586
587 // Called at pmic adpt layer init phase
588 // The phase what scheduler is running(BMT task is created)
589 void (*enable_intr)(void);
590
591 // Control charge enable/disable
592 // Called at any time, any context
593 kal_bool (*charge_enable)(kal_bool enable);
594
595 // The unit is in mA ==> 1000 means 1A
596 // Called at any time, any context
597 // a most close, but not exceeded charge current will be selected
598 // 500mA means can NOT large than 500mA, but most close to 500mA
599 kal_bool (*set_charge_current)(kal_int32 charge_current);
600
601 // Whether the external charger can measure the passed-in charging factor
602 bmt_chr_fac_measure_support_enum (*get_chr_fac_measure_support)(bmt_chr_fac_enum chr_fac);
603
604 // Whether the external charger can check the passed-in charging factor
605 bmt_chr_fac_check_support_enum (*get_chr_fac_check_support)(bmt_chr_fac_enum chr_fac);
606
607 // Pass information to charger device
608 // Charger device can calculate the charger status through the passed-in info
609 void (*check_chr_status)(BATPHYStruct *pBatPhysStat);
610
611 // Charger return calculated charger status
612 // Usually, charger device should keep the chr status before reset_chr_status() is called
613 // The return kal_uint32 is union of all charging factors status
614 kal_uint32 (*get_chr_status)(void);
615
616 // The return unit is uV ==> 1000000 means 1.0V
617 // The passed-in parameter is the information measured by HOST,
618 // ext charger driver need this info to calculate
619 kal_int32 (*get_vbat)(BATPHYStruct *pBatPhysStat);
620
621 // The return unit is uA ==> 1000000 means 1A
622 // The passed-in parameter is the information measured by HOST,
623 // ext charger driver need this info to calculate
624 kal_int32 (*get_isense)(BATPHYStruct *pBatPhysStat);
625
626 // The return unit is uV ==> 1000000 means 1.0V
627 // The passed-in parameter is the information measured by HOST,
628 // ext charger driver need this info to calculate
629 kal_int32 (*get_vcharger)(BATPHYStruct *pBatPhysStat);
630
631 // Return the calculated NTC value of battery temperature
632 // The passed-in parameter is the information measured by HOST,
633 // ext charger driver need this info to calculate
634 kal_int32 (*get_bat_temp)(BATPHYStruct *pBatPhysStat);
635
636 // Return if charge full
637 // The unit is vbat is uV ==> 1000000 means 1.0V
638 // Return KAL_TRUE: Charge full
639 // Return KAL_FALSE: Not charge full
640 kal_bool (*get_charge_full)(kal_int32 vbat);
641
642 // Return if it's under extreme temperature
643 // Return KAL_TRUE: It's under extreme temperature
644 // Return KAL_FALSE: It's NOT under extreme temperature
645 kal_bool (*get_charge_under_extremetmp)(kal_int32 battmp);
646
647 // Return if charge full when under extreme temperature
648 // The unit is vbat is uV ==> 1000000 means 1.0V
649 // Return KAL_TRUE: Charge full
650 // Return KAL_FALSE: Not charge full
651 kal_bool (*get_charge_extremetmp_full)(kal_int32 vbat);
652
653 // Return if charge should recharge when under extreme temperature
654 // The unit is vbat is uV ==> 1000000 means 1.0V
655 // Return KAL_TRUE: Should recharge
656 // Return KAL_FALSE: Should NT recharge
657 kal_bool (*get_charge_extremetmp_recharge)(kal_int32 vbat);
658
659 // Return KAL_TRUE: Need to hold charging
660 // Return KAL_FALSE: Do NOT need to hold charging
661 // The condition to hold charging: Talking mode ...
662 kal_bool (*get_charge_hold)(BATPHYStruct *pBatPhysStat);
663
664 // Whether the external charger can handle the specific charging battery state
665 bmt_chr_fac_check_support_enum(*get_chr_batt_state_transit_support)(kal_uint32 curr_chr_batt_state);
666
667 // Perform charging battery state transit
668 // curr_chr_batt_state: Current state
669 // chr_on: Current CHR_EN state
670 void (*chr_batt_state_transit)(kal_uint32 curr_chr_batt_state, kal_bool chr_en);
671
672 // Get current charging battery state PRE, FAST(CC), TOPOFF(CV), FULL, ...
673 kal_uint32 (*get_curr_chr_batt_state)(BATPHYStruct *pBatPhysStat);
674
675 // Get custom charge current according to specific charger
676 kal_uint32 (*get_specific_chr_current)(bmt_charger_type charger);
677
678 // Whether the vbat is higher than specific full check vaule or not
679 // Return KAL_TRUE: higher than specific full voltage
680 // Return KAL_FALSE: lower than specific full voltage
681 kal_bool (*get_vbat_specific_full_voltage_state)(kal_int32 vbat); //__DRV_BMT_CHARGING_COMPLETE_MSG__
682
683}bmt_ext_charger;
684
685// External charger custom table V1.0
686typedef struct{
687 // Control enable/disable charger
688 void (*charge_enable)(kal_bool enable);
689
690 // Set charge current
691 // The unit is mA ==> 1000 means 1A
692 void (*charge_current)(kal_int32 current);
693
694 // Return KAL_TRUE: Charger think battery is full
695 // Return KAL_FALSE: Charger think battery is NOT full
696 kal_bool (*charge_full_ind)(kal_int32 vbat);
697
698 // Return KAL_TRUE: Charger thing it's under extreme temperature
699 // Return KAL_FALSE: Charger thing it's NOT under extreme temperature
700 kal_bool (*charge_under_extremetmp_ind)(kal_int32 battmp);
701
702 // Return KAL_TRUE: Charger think battery is full if it's under extreme temperature
703 // Return KAL_FALSE: Charger think battery is NOT if it's full under extreme temperature
704 kal_bool (*charge_extremetmp_full_ind)(kal_int32 vbat);
705
706 // Return KAL_TRUE: Charger think battery should be recharged if it's under extreme temperature
707 // Return KAL_FALSE: Charger think battery should NOT be recharged if it's under extreme temperature
708 kal_bool (*charge_extremetmp_recharge_ind)(kal_int32 vbat);
709
710 // Number of charge current level (Ex: 100mA, 150mA, 500mA ...)
711 kal_uint32 charge_current_num;
712
713 // The current must be listed from largest to smallest
714 // Ex: 0: 500mA; 1: 250mA; 2: 100mA ...
715 kal_uint32 *charge_current_table;
716
717 // Return the custom charge current for specific charger type, the unit is mA
718 kal_uint32 (*get_custom_charge_current)(bmt_charger_type charger);
719
720 // Whether the charge source is good
721 // Return KAL_TRUE: Charge source is good
722 // Return KAL_FALSE: Charge source is NOT good
723 kal_bool (*charge_source_good)(void);
724
725 // Whether the vbat is higher than specific full check vaule or not
726 // Return KAL_TRUE: higher than specific full voltage
727 // Return KAL_FALSE: lower than specific full voltage
728 kal_bool (*vbat_specific_full_check_voltage)(kal_int32 vbat); //__DRV_BMT_CHARGING_COMPLETE_MSG__
729
730}bmt_ext_charger_custom_config;
731
732
733// For external charger mechanism integration
734
735
736// For external charger detection integration
737typedef struct
738{
739 // This API report charger in/out and AC or USB type together
740 // This API may be called at anytime
741 // Ex: Before scheduler is running (Boot init phase)
742 // Called at boot time (No scheduler is running)
743 // Called in HISR (Drv_HISR and system HISR)
744 // Called in Task
745 charger_usb_present_enum (*det_charger_present)(void);
746
747 // This API is for PWIC to register HISR handler for charger
748 // PWIC will use det_charger_present() to determine whether it is in/out
749 void (*reg_chr_hisr)(void (chr_hisr_callback)(void));
750
751 // This API is for PWIC to register HISR handler for usb
752 // PWIC will use det_charger_present() to determine whether it is in/out
753 void (*reg_usb_hisr)(void (usb_hisr_callback)(void));
754
755 // This API is to set S/W debounce time for charger cable
756 // The uint of deb_time is in 10ms (GPT tick)
757 void (*set_chr_deb_time)(kal_uint32 deb_time);
758
759 // This API is to set S/W debounce time for usb cable
760 // The uint of deb_time is in 10ms (GPT tick)
761 void (*set_usb_deb_time)(kal_uint32 deb_time);
762
763 // This API is to report whether USB detection is supported or NOT
764 kal_bool (*support_usb_det)(void);
765
766 // Init the external charger detection mechanism
767 // The API is called at boot phase
768 // After this call, we should be able to call det_charger_present()
769 // Provider need to guarantee this
770 void (*drv_init)(void);
771
772 // The API is called at pmic adpt layer init phase
773 void (*enable_intr)(void);
774
775}bmt_ext_charger_det;
776
777typedef enum
778{
779 EXT_CABLE_PATH_CHARGER,
780 EXT_CABLE_PATH_STD_USB,
781 EXT_CABLE_PATH_HIGH_CURRENT_USB,
782 EXT_CABLE_PATH_UART,
783 EXT_CABLE_PATH_EARPHONE,
784 EXT_CABLE_PATH_TV_OUT,
785 EXT_CABLE_PATH_USB_OTG,
786 EXT_CABLE_PATH_FAC_UART,
787 EXT_CABLE_PATH_FAC_USB,
788 EXT_CABLE_PATH_CS_CHARGER, // Customer specific charger
789 EXT_CABLE_PATH_MAX
790}ext_cable_path_enum;
791
792typedef struct
793{
794 // Factory mode API
795 // Force switch external cable to specific path for test
796 void (*set_path)(ext_cable_path_enum path);
797
798 // Factory mode API
799 // Return current external cable path
800 ext_cable_path_enum (*get_curr_path)(void);
801
802 // ASSERT mode API
803 // Called when system enter ASSERT,
804 // the ext cable mechanism should switch cable path for memory dump
805 void (*ext_cable_force_set_path)(ext_cable_path_enum path);
806
807 // API for specific workaround: Turn on/off ext cable path
808 void (*ext_cable_WA_set_path)(ext_cable_path_enum path, kal_bool on);
809
810}ext_cable_det_fac_if;
811
812
813// For external charger detection integration
814
815extern kal_uint8 bmt_bmtid_adc_handle[BMT_ADC_MAX_CHANNEL_TOTAL];
816extern kal_uint8 bmt_adc_handle;
817
818// MoDIS parser skip start
819// The following APIs are impmemented in custom folder, which will be inclucded in MoDIS
820/*usb charge*/
821extern kal_bool bmt_support_usb_charge(void);
822extern kal_int32 bmt_get_chr_usb_detect_volt(void);
823// MoDIS parser skip end
824
825// MoDIS parser skip start
826/*charing parameters*/
827// MoDIS parser skip end
828
829#if defined(__GENERAL_EXTERNAL_CHARGER__)
830extern bmt_ext_charger *ext_charger; // Variable in pwic.c
831extern bmt_ext_charger *bmt_get_ext_charger(void);
832extern bmt_ext_charger_custom_config *bmt_ext_charger_get_custom_config(void);
833#endif // #if defined(__GENERAL_EXTERNAL_CHARGER__)
834
835extern ext_cable_det_fac_if *custom_get_ext_cable_fac(void);
836
837#if defined(__DRV_EXT_CHARGER_DETECTION__)
838extern bmt_ext_charger_det *ext_charger_det;
839extern bmt_ext_charger_det *bmt_custom_get_ext_charger_det(void);
840#endif // #if defined(__DRV_EXT_CHARGER_DETECTION__)
841
842extern kal_uint8 BMT_MAX_CHANNEL; // The ADC channel number in BMT (Used for charging factor monitoring)
843extern BMTStruct BMT;
844
845#if defined(DRV_ADC_CALIBRATION_EFUSE)
846extern kal_bool bmt_read_calibration_data(ADC_CALIDATA *adc_cali);
847#endif //#if defined(DRV_ADC_CALIBRATION_EFUSE)
848
849extern void BMT_VbatInHISR(void);
850extern kal_bool bmt_is_bat_on(void);
851
852extern kal_bool BMT_ObtainBMTPHYSTAT(BATPHYStruct *BATPHYS);
853extern void bmt_chr_force_enable(kal_bool enable);
854extern kal_bool bmt_is_chr_valid(void);
855extern kal_bool bmt_get_chr_cv_det(void);
856#endif // End of #ifndef _BMT_H
857