bmt.h 22.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------
 *    bmt.h
 *
 * Project:
 * --------
 *   Maui_Software
 *
 * Description:
 * ------------
 *   This file is intends for Battery Management Task.
 *
 * Author:
 * -------
 * -------
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/
#ifndef _BMT_H
#define _BMT_H

#include "kal_general_types.h"
#include "kal_public_defs.h"
#include "dcl.h"
#include "adc_cali.h"

#define ADC_BMT_VBAT            0
#define ADC_BMT_VISENSE         1
#define ADC_BMT_VBATTMP         2
#define ADC_BMT_VCHARGER	    3
#define ADC_BMT_MAX_CHANNEL_TOTAL   4
//#define BMT_MAX_CHANNEL_TOTAL       ADC_BMT_MAX_CHANNEL_TOTAL  // backward compatible

/*
#ifdef __BMT_CHECK_CHARGER__
#define BMT_MAX_CHANNEL    4
#else
#define BMT_MAX_CHANNEL    3
#endif
*/
#define BMT_ADC_VBAT            0
#define BMT_ADC_VISENSE         1
#define BMT_ADC_VBATTMP         2
#define BMT_ADC_VCHARGER	    3
#define BMT_ADC_MAX_CHANNEL_TOTAL   4

/*precharge threshold*/
#define BMT_PRECHARGE_THRESHOLD  3300000

#if defined(__TC01__)
/* under construction !*/
#endif // #if defined(__TC01__)

/*BatType*/
#define  LIBAT                            0
#define  NIBAT                            1

/*extern charger state*/
#define  DETECTCHRIN                      0x0
#define  DETECTCHROUT                     !DETECTCHRIN

/*BMT Minor STATE. When Charger is plugged in, charge is enable or not?*/
#define  PMIC_CHARGEOFF                   0   /*pmictrl_state*/
#define  PMIC_CHARGEON                    1   

/*MS Mode*/
#define idle_mode                         0
#define talk_mode                         1
#define swoff_mode                        2


#define BMT_HIGH_VCHG_THRESHOLD 100000

#if defined(DRV_BMT_HIGH_VCHG_ADAPTIVE_CHARGE_CURRENT_SUPPORT)
#define VCHG_VOL_LEVEL      7
#define VCHG_PARAMTER_COUNT 3

typedef struct{
    kal_uint32 VCHG_HV_VTH;
    kal_int32 HIGH_VCHG_TABLE[VCHG_VOL_LEVEL][VCHG_PARAMTER_COUNT];
}bmt_customized_high_vchg_struct;

extern kal_bool High_Vchg_Safety_Timer_Set;
extern bmt_customized_high_vchg_struct *bmt_high_vchg_para;
extern kal_uint32 bmt_total_charge_time;
extern kal_bool bmt_safety_timer_config;
extern kal_int32 Pre_VCharge_AVG;
extern kal_int32 Cur_VCharge_MAX;
extern bmt_customized_high_vchg_struct *bmt_get_customized_high_vchg_para(void);

#endif // End of #if defined(DRV_BMT_HIGH_VCHG_ADAPTIVE_CHARGE_CURRENT_SUPPORT)

typedef enum{
	CHARGER_PRESENT,
//#if defined(__CHINA_CHARGER_STANDARD__)
	CHARGER_PRESENT_NON,
//#endif
	USB_PRESENT,
	NO_PRESENT
}charger_usb_present_enum;

typedef enum{
	BMT_AC_CHR,
	BMT_USB_CHR
}bmt_charger_type;

typedef enum {
	bmt_chr_in=0,
   bmt_chr_out,
   bmt_chr_uninit = 0xff
}Charger_Status;

typedef enum {
	VBAT_UEM_CHR_OUT=0,
	VBAT_UEM_CHR_OUT_FIRST=1,
	VBAT_UEM_CHR_IN=2,
	VBAT_UEM_CHR_IN_FISRT=3
}VBAT_UEM_CHR_ENUM;

typedef enum 
{
   CHR_CURRENT_50=0,
   CHR_CURRENT_90,
   CHR_CURRENT_150,
   CHR_CURRENT_225,
   CHR_CURRENT_300,
   CHR_CURRENT_450,
   CHR_CURRENT_650,
   CHR_CURRENT_800
}pmic_charging_current;

typedef struct {
   kal_uint8               bat_state;
   kal_uint8               pmictrl_state;   /*pmic control on,off*/
   kal_uint8               call_state;   /*mobile state*/
  // kal_uint8               PWRon;
   kal_uint8               BatType;
   kal_uint8               EINT2STATE;
   kal_uint8               highfull;
   VBAT_UEM_CHR_ENUM		     VBAT_UEM; // state of UEM VBAT measurement 
   kal_hisrid              hisr;
} BMTStruct;

typedef struct {
   kal_int32 VBAT;
   kal_int32 ICHARGE;
   kal_int32 BATTMP;
   kal_int32 VCHARGER;
   kal_int32 ISense_Offset;
   //kal_uint8 BATTYPE;
} BATPHYStruct;

#if defined(__CHARGER_USB_DETECT_WIHT_ONE_EINT__)
typedef struct{
	kal_bool chr_usb_state;	// indicate cable is plugged in or not for eint trigger level setting
	volatile charger_usb_present_enum chr_usb_present;	// is charger or usb presnet or not
	kal_int32 chr_usb_adc_handle;	// handle of dcl adc scheduler
	kal_uint8 chr_usb_eint;	// eint number for charger and usb
	kal_uint8 chr_usb_adc;	// adc channel to measure charger or usb
	kal_int32 chr_usb_volt;	// voltage to distinguish between charger with usb
}chr_usb_detect_struct;
#endif

// For external charger mechanism integration

// The enum is to indicate whether the charging factor is measured by HOST or Charger device
typedef enum
{
  CHR_FACTOR_MEASURE_NONE =             0x00000000,   // Both NOT support, TBD
  CHR_FACTOR_MEASURE_BY_HOST =          0x00000001,   // BIT00, HOST measure the specific charging factor
  CHR_FACTOR_MEASURE_BY_CHARGER_DEV =   0x00000002    // BIT01, Charger device measure the specific charging factor

}bmt_chr_fac_measure_support_enum;

// The enum is to indicate whether the charging factor error check is done by HOST or charger device
typedef enum
{
  BMT_CHR_FACTOR_CHECK_NONE =           0x00000000,   // Both NOT support, TBD
  BMT_CHR_FACTOR_CHECK_BY_HOST =        0x00000001,   // BIT00, HOST perform charging factor error check
  BMT_CHR_FACTOR_CHECK_BY_CHARGER_DEV = 0x00000002    // BIT01, Charger device perform charging facotr error check

}bmt_chr_fac_check_support_enum;

// The enum defines the charging factors that charging process need to check
typedef enum
{
  BMT_CHR_FACTOR_VBAT,               // Charging factor: VBAT
  BMT_CHR_FACTOR_ISENSE,             // Charging factor: VISENSE
  BMT_CHR_FACTOR_BATTMP,             // Charging factor: VBAT temperature
  BMT_CHR_FACTOR_VCHARGER,           // Charging factor: VCHARGER
  BMT_CHR_FACTOR_CHARGER_OVP,        // Charging factor: Charger OVP
  BMT_CHR_FACTOR_CHARGE_FULL,        // Charging factor: Charge full
  BMT_CHR_FACTOR_UNDER_EXTREMETMP,        // Charging factor: Extreme temperature
  BMT_CHR_FACTOR_CHARGE_EXTREMETMP_FULL,        // Charging factor: Charge full under extreme temperature
  BMT_CHR_FACTOR_CHARGE_EXTREMETMP_RECHARGE,        // Charging factor: Should recharge under extreme temperature
  BMT_CHR_FACTOR_HOLD,               // Charging factor: Charging hold
  BMT_CHR_FACTOR_CHR_BATT_STATE,     // Charging factor: charging state: PRE, FAST(CC), TOPOFF(CV), FULL ...

  BMT_CHR_FACTOR_MAX
}bmt_chr_fac_enum;

typedef struct
{

  // Driver init
  // Called at drv init phase
  void (*drv_init)(void);

  // Called at pmic adpt layer init phase
  // The phase what scheduler is running(BMT task is created)
  void (*enable_intr)(void);

  // Control charge enable/disable
  // Called at any time, any context
  kal_bool (*charge_enable)(kal_bool enable);

  // The unit is in mA ==> 1000 means 1A
  // Called at any time, any context
  // a most close, but not exceeded charge current will be selected
  // 500mA means can NOT large than 500mA, but most close to 500mA
  kal_bool (*set_charge_current)(kal_int32 charge_current);

  // Whether the external charger can measure the passed-in charging factor
  bmt_chr_fac_measure_support_enum (*get_chr_fac_measure_support)(bmt_chr_fac_enum chr_fac);

  // Whether the external charger can check the passed-in charging factor
  bmt_chr_fac_check_support_enum (*get_chr_fac_check_support)(bmt_chr_fac_enum chr_fac);

  // Pass information to charger device
  // Charger device can calculate the charger status through the passed-in info
  void (*check_chr_status)(BATPHYStruct *pBatPhysStat);

  // Charger return calculated charger status
  // Usually, charger device should keep the chr status before reset_chr_status() is called
  // The return kal_uint32 is union of all charging factors status
  kal_uint32 (*get_chr_status)(void);

  // The return unit is uV ==> 1000000 means 1.0V
  // The passed-in parameter is the information measured by HOST,
  // ext charger driver need this info to calculate
  kal_int32 (*get_vbat)(BATPHYStruct *pBatPhysStat);

  // The return unit is uA ==> 1000000 means 1A
  // The passed-in parameter is the information measured by HOST,
  // ext charger driver need this info to calculate
  kal_int32 (*get_isense)(BATPHYStruct *pBatPhysStat);

  // The return unit is uV ==> 1000000 means 1.0V
  // The passed-in parameter is the information measured by HOST,
  // ext charger driver need this info to calculate
  kal_int32 (*get_vcharger)(BATPHYStruct *pBatPhysStat);

  // Return the calculated NTC value of battery temperature
  // The passed-in parameter is the information measured by HOST,
  // ext charger driver need this info to calculate
  kal_int32 (*get_bat_temp)(BATPHYStruct *pBatPhysStat);

  // Return if charge full
  // The unit is vbat is uV ==> 1000000 means 1.0V
  // Return KAL_TRUE: Charge full
  // Return KAL_FALSE: Not charge full
  kal_bool (*get_charge_full)(kal_int32 vbat);

  // Return if it's under extreme temperature
  // Return KAL_TRUE: It's under extreme temperature
  // Return KAL_FALSE: It's NOT under extreme temperature
  kal_bool (*get_charge_under_extremetmp)(kal_int32 battmp);

  // Return if charge full when under extreme temperature
  // The unit is vbat is uV ==> 1000000 means 1.0V
  // Return KAL_TRUE: Charge full
  // Return KAL_FALSE: Not charge full
  kal_bool (*get_charge_extremetmp_full)(kal_int32 vbat);

  // Return if charge should recharge when under extreme temperature
  // The unit is vbat is uV ==> 1000000 means 1.0V
  // Return KAL_TRUE: Should recharge
  // Return KAL_FALSE: Should NT recharge
  kal_bool (*get_charge_extremetmp_recharge)(kal_int32 vbat);

  // Return KAL_TRUE: Need to hold charging
  // Return KAL_FALSE: Do NOT need to hold charging
  // The condition to hold charging: Talking mode ...
  kal_bool (*get_charge_hold)(BATPHYStruct *pBatPhysStat);

  // Whether the external charger can handle the specific charging battery state
  bmt_chr_fac_check_support_enum(*get_chr_batt_state_transit_support)(kal_uint32 curr_chr_batt_state);

  // Perform charging battery state transit
  // curr_chr_batt_state: Current state
  // chr_on: Current CHR_EN state
  void (*chr_batt_state_transit)(kal_uint32 curr_chr_batt_state, kal_bool chr_en);

  // Get current charging battery state PRE, FAST(CC), TOPOFF(CV), FULL, ...
  kal_uint32 (*get_curr_chr_batt_state)(BATPHYStruct *pBatPhysStat);

  // Get custom charge current according to specific charger
  kal_uint32 (*get_specific_chr_current)(bmt_charger_type charger);

  // Whether the vbat is higher than specific full check vaule or not
  // Return KAL_TRUE: higher than specific full voltage
  // Return KAL_FALSE: lower than specific full voltage
  kal_bool (*get_vbat_specific_full_voltage_state)(kal_int32 vbat); //__DRV_BMT_CHARGING_COMPLETE_MSG__

}bmt_ext_charger;

// External charger custom table V1.0
typedef struct{
  // Control enable/disable charger
  void (*charge_enable)(kal_bool enable);

  // Set charge current
  // The unit is mA ==> 1000 means 1A
  void (*charge_current)(kal_int32 current);

  // Return KAL_TRUE: Charger think battery is full
  // Return KAL_FALSE: Charger think battery is NOT full
  kal_bool (*charge_full_ind)(kal_int32 vbat);

  // Return KAL_TRUE: Charger thing it's under extreme temperature
  // Return KAL_FALSE: Charger thing it's NOT under extreme temperature
  kal_bool (*charge_under_extremetmp_ind)(kal_int32 battmp);

  // Return KAL_TRUE: Charger think battery is full if it's under extreme temperature
  // Return KAL_FALSE: Charger think battery is NOT if it's full under extreme temperature
  kal_bool (*charge_extremetmp_full_ind)(kal_int32 vbat);

  // Return KAL_TRUE: Charger think battery should be recharged if it's under extreme temperature
  // Return KAL_FALSE: Charger think battery should NOT be recharged if it's under extreme temperature
  kal_bool (*charge_extremetmp_recharge_ind)(kal_int32 vbat);

  // Number of charge current level (Ex: 100mA, 150mA, 500mA ...)
  kal_uint32 charge_current_num;

  // The current must be listed from largest to smallest
  // Ex: 0: 500mA; 1: 250mA; 2: 100mA ...
  kal_uint32 *charge_current_table;

  // Return the custom charge current for specific charger type, the unit is mA
  kal_uint32 (*get_custom_charge_current)(bmt_charger_type charger);

  // Whether the charge source is good
  // Return KAL_TRUE: Charge source is good
  // Return KAL_FALSE: Charge source is NOT good
  kal_bool (*charge_source_good)(void);

  // Whether the vbat is higher than specific full check vaule or not
  // Return KAL_TRUE: higher than specific full voltage
  // Return KAL_FALSE: lower than specific full voltage
  kal_bool (*vbat_specific_full_check_voltage)(kal_int32 vbat); //__DRV_BMT_CHARGING_COMPLETE_MSG__

}bmt_ext_charger_custom_config;


// For external charger mechanism integration


// For external charger detection integration
typedef struct
{
  // This API report charger in/out and AC or USB type together
  // This API may be called at anytime
  // Ex: Before scheduler is running (Boot init phase)
  //     Called at boot time (No scheduler is running)
  //     Called in HISR (Drv_HISR and system HISR)
  //     Called in Task
  charger_usb_present_enum (*det_charger_present)(void);

  // This API is for PWIC to register HISR handler for charger
  // PWIC will use det_charger_present() to determine whether it is in/out
  void (*reg_chr_hisr)(void (chr_hisr_callback)(void));

  // This API is for PWIC to register HISR handler for usb
  // PWIC will use det_charger_present() to determine whether it is in/out
  void (*reg_usb_hisr)(void (usb_hisr_callback)(void));

  // This API is to set S/W debounce time for charger cable
  // The uint of deb_time is in 10ms (GPT tick)
  void (*set_chr_deb_time)(kal_uint32 deb_time);

  // This API is to set S/W debounce time for usb cable
  // The uint of deb_time is in 10ms (GPT tick)
  void (*set_usb_deb_time)(kal_uint32 deb_time);

  // This API is to report whether USB detection is supported or NOT
  kal_bool (*support_usb_det)(void);

  // Init the external charger detection mechanism
  // The API is called at boot phase
  // After this call, we should be able to call det_charger_present()
  // Provider need to guarantee this
  void (*drv_init)(void);

  // The API is called at pmic adpt layer init phase
  void (*enable_intr)(void);

}bmt_ext_charger_det;

typedef enum
{
  EXT_CABLE_PATH_CHARGER,
  EXT_CABLE_PATH_STD_USB,
  EXT_CABLE_PATH_HIGH_CURRENT_USB,
  EXT_CABLE_PATH_UART,
  EXT_CABLE_PATH_EARPHONE,
  EXT_CABLE_PATH_TV_OUT,
  EXT_CABLE_PATH_USB_OTG,
  EXT_CABLE_PATH_FAC_UART,
  EXT_CABLE_PATH_FAC_USB,
  EXT_CABLE_PATH_CS_CHARGER,  // Customer specific charger
  EXT_CABLE_PATH_MAX
}ext_cable_path_enum;

typedef struct
{
  // Factory mode API
  // Force switch external cable to specific path for test
  void (*set_path)(ext_cable_path_enum path);

  // Factory mode API
  // Return current external cable path
  ext_cable_path_enum (*get_curr_path)(void);

  // ASSERT mode API
  // Called when system enter ASSERT, 
  // the ext cable mechanism should switch cable path for memory dump
  void (*ext_cable_force_set_path)(ext_cable_path_enum path);

  // API for specific workaround: Turn on/off ext cable path
  void (*ext_cable_WA_set_path)(ext_cable_path_enum path, kal_bool on);

}ext_cable_det_fac_if;


// For external charger detection integration

extern kal_uint8  bmt_bmtid_adc_handle[BMT_ADC_MAX_CHANNEL_TOTAL];
extern DCL_HANDLE  bmt_adc_handle;

// MoDIS parser skip start
// The following APIs are impmemented in custom folder, which will be inclucded in MoDIS
/*usb charge*/
extern kal_bool bmt_support_usb_charge(void);
extern kal_int32 bmt_get_chr_usb_detect_volt(void);
// MoDIS parser skip end

// MoDIS parser skip start
/*charing parameters*/
// MoDIS parser skip end

#if defined(__GENERAL_EXTERNAL_CHARGER__)
extern bmt_ext_charger *ext_charger; // Variable in pwic.c
extern bmt_ext_charger *bmt_get_ext_charger(void);
extern bmt_ext_charger_custom_config *bmt_ext_charger_get_custom_config(void);
#endif // #if defined(__GENERAL_EXTERNAL_CHARGER__)

extern ext_cable_det_fac_if *custom_get_ext_cable_fac(void);

#if defined(__DRV_EXT_CHARGER_DETECTION__)
extern bmt_ext_charger_det *ext_charger_det;
extern bmt_ext_charger_det *bmt_custom_get_ext_charger_det(void);
#endif // #if defined(__DRV_EXT_CHARGER_DETECTION__)

extern kal_uint8 BMT_MAX_CHANNEL;      // The ADC channel number in BMT (Used for charging factor monitoring)
#ifdef __CHARGER_USB_DETECT_WIHT_ONE_EINT__
extern chr_usb_detect_struct chr_usb_detect;
#endif
extern BMTStruct BMT;

#if defined(DRV_ADC_CALIBRATION_EFUSE)
extern kal_bool bmt_read_calibration_data(ADC_CALIDATA *adc_cali);
#endif //#if defined(DRV_ADC_CALIBRATION_EFUSE)

extern void BMT_VbatInHISR(void);
extern kal_bool bmt_is_bat_on(void);

extern kal_bool BMT_ObtainBMTPHYSTAT(BATPHYStruct *BATPHYS);
extern void bmt_chr_force_enable(kal_bool enable);
extern kal_bool bmt_is_chr_valid(void);
extern kal_bool bmt_get_chr_cv_det(void);
#endif // End of #ifndef _BMT_H