/***************************************************************************** * * Filename: * --------- * charging_pmic.c * * Project: * -------- * ALPS_Software * * Description: * ------------ * This file implements the interface between BMT and ADC scheduler. * * Author: * ------- * Oscar Liu * *============================================================================ * $Revision: 1.0 $ * $Modtime: 11 Aug 2005 10:28:16 $ * $Log: //mtkvs01/vmdata/Maui_sw/archives/mcu/hal/peripheral/inc/bmt_chr_setting.h-arc $ * * 03 05 2015 wy.chuang * [ALPS01921641] [L1_merge] for PMIC and charging * . * HISTORY * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! *------------------------------------------------------------------------------ *------------------------------------------------------------------------------ * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! *============================================================================ ****************************************************************************/ #include #include "ncp1854.h" #include #include #include #include #include #include #include #include #include #include //#include //mtk71259 build error 20140523 #include #include #include #include #include // ============================================================ // //define // ============================================================ // #define STATUS_OK 0 #define STATUS_UNSUPPORTED -1 #define GETARRAYNUM(array) (sizeof(array)/sizeof(array[0])) // ============================================================ // //global variable // ============================================================ // int gpio_off_dir = GPIO_DIR_OUT; int gpio_off_out = GPIO_OUT_ONE; int gpio_on_dir = GPIO_DIR_OUT; int gpio_on_out = GPIO_OUT_ZERO; /*#ifndef GPIO_CHR_SPM_PIN GPIO_SWCHARGER_EN_PIN #define GPIO_CHR_SPM_PIN 65 #endif */ #if defined(MTK_WIRELESS_CHARGER_SUPPORT) #define WIRELESS_CHARGER_EXIST_STATE 0 #if defined(GPIO_PWR_AVAIL_WLC) kal_uint32 wireless_charger_gpio_number = GPIO_PWR_AVAIL_WLC; #else kal_uint32 wireless_charger_gpio_number = 0; #endif #endif static CHARGER_TYPE g_charger_type = CHARGER_UNKNOWN; kal_bool charging_type_det_done = KAL_TRUE; //As 82 platform mach/charging.h could not cover all voltage setting, just hardcoded below settings const kal_uint32 VBAT_CV_VTH[]= { 3300000, 3325000, 3350000, 3375000, 3400000, 3425000, 3450000, 3475000, 3500000, 3525000, 3550000, 3575000, 3600000, 3625000, 3650000, 3675000, 3700000, 3725000, 3750000, 3775000, 3800000, 3825000, 3850000, 3875000, 3900000, 3925000, 3950000, 3975000, 4000000, 4025000, 4050000, 4075000, 4100000, 4125000, 4150000, 4175000, 4200000, 4225000, 4250000, 4275000, 4300000, 4325000, 4350000, 4375000, 4400000, 4425000, 4450000, 4475000, }; /* const kal_uint32 CS_VTH[]= { CHARGE_CURRENT_450_00_MA, CHARGE_CURRENT_550_00_MA, CHARGE_CURRENT_650_00_MA, CHARGE_CURRENT_750_00_MA, CHARGE_CURRENT_850_00_MA, CHARGE_CURRENT_950_00_MA, CHARGE_CURRENT_1050_00_MA, CHARGE_CURRENT_1150_00_MA, CHARGE_CURRENT_1250_00_MA, CHARGE_CURRENT_1350_00_MA, CHARGE_CURRENT_1450_00_MA, CHARGE_CURRENT_1550_00_MA, CHARGE_CURRENT_1650_00_MA, CHARGE_CURRENT_1750_00_MA, CHARGE_CURRENT_1850_00_MA, CHARGE_CURRENT_1950_00_MA }; */ /* hardcoded current define which defined in NCP1854 IC spec, as common define doesnot cover all define * double confirmed with onsemi register set in spec has issue,below is the correct setting */ const kal_uint32 CS_VTH[]= { 45000, 50000, 60000, 70000, 80000, 90000, 100000, 110000, 120000, 130000, 140000, 150000, 160000, 170000, 180000, 190000 }; const kal_uint32 INPUT_CS_VTH[]= { CHARGE_CURRENT_100_00_MA, CHARGE_CURRENT_500_00_MA }; const kal_uint32 INPUT_CS_VTH_TA[]= { CHARGE_CURRENT_600_00_MA, CHARGE_CURRENT_700_00_MA, CHARGE_CURRENT_800_00_MA, CHARGE_CURRENT_900_00_MA, CHARGE_CURRENT_1000_00_MA, CHARGE_CURRENT_1100_00_MA, CHARGE_CURRENT_1200_00_MA, CHARGE_CURRENT_1300_00_MA, CHARGE_CURRENT_1400_00_MA, CHARGE_CURRENT_1500_00_MA, CHARGE_CURRENT_1600_00_MA, 170000, 180000, 190000, 200000 }; const kal_uint32 VCDT_HV_VTH[]= { BATTERY_VOLT_04_200000_V, BATTERY_VOLT_04_250000_V, BATTERY_VOLT_04_300000_V, BATTERY_VOLT_04_350000_V, BATTERY_VOLT_04_400000_V, BATTERY_VOLT_04_450000_V, BATTERY_VOLT_04_500000_V, BATTERY_VOLT_04_550000_V, BATTERY_VOLT_04_600000_V, BATTERY_VOLT_06_000000_V, BATTERY_VOLT_06_500000_V, BATTERY_VOLT_07_000000_V, BATTERY_VOLT_07_500000_V, BATTERY_VOLT_08_500000_V, BATTERY_VOLT_09_500000_V, BATTERY_VOLT_10_500000_V }; // ============================================================ // // function prototype // ============================================================ // // ============================================================ // //extern variable // ============================================================ // // ============================================================ // //extern function // ============================================================ // extern kal_uint32 upmu_get_reg_value(kal_uint32 reg); extern bool mt_usb_is_device(void); extern void Charger_Detect_Init(void); extern void Charger_Detect_Release(void); extern int hw_charging_get_charger_type(void); extern void mt_power_off(void); extern kal_uint32 mt6311_get_chip_id(void); extern int is_mt6311_exist(void); extern int is_mt6311_sw_ready(void); kal_uint32 current_high_flag = 0; // ============================================================ // #ifdef MTK_POWER_EXT_DETECT static kal_uint32 mt_get_board_type(void) { /* * Note: Don't use it in IRQ context */ #if 1 static int board_type = MT_BOARD_NONE; if (board_type != MT_BOARD_NONE) return board_type; spin_lock(&mt_board_lock); /* Enable AUX_IN0 as GPI */ mt_set_gpio_ies(GPIO_PHONE_EVB_DETECT, GPIO_IES_ENABLE); /* Set internal pull-down for AUX_IN0 */ mt_set_gpio_pull_select(GPIO_PHONE_EVB_DETECT, GPIO_PULL_DOWN); mt_set_gpio_pull_enable(GPIO_PHONE_EVB_DETECT, GPIO_PULL_ENABLE); /* Wait 20us */ udelay(20); /* Read AUX_INO's GPI value*/ mt_set_gpio_mode(GPIO_PHONE_EVB_DETECT, GPIO_MODE_00); mt_set_gpio_dir(GPIO_PHONE_EVB_DETECT, GPIO_DIR_IN); if (mt_get_gpio_in(GPIO_PHONE_EVB_DETECT) == 1) { /* Disable internal pull-down if external pull-up on PCB(leakage) */ mt_set_gpio_pull_enable(GPIO_PHONE_EVB_DETECT, GPIO_PULL_DISABLE); board_type = MT_BOARD_EVB; } else { /* Disable internal pull-down if external pull-up on PCB(leakage) */ mt_set_gpio_pull_enable(GPIO_PHONE_EVB_DETECT, GPIO_PULL_DISABLE); board_type = MT_BOARD_PHONE; } spin_unlock(&mt_board_lock); pr_notice("[Kernel] Board type is %s\n", (board_type == MT_BOARD_EVB) ? "EVB" : "PHONE"); return board_type; #else return MT_BOARD_EVB; #endif } #endif kal_uint32 charging_value_to_parameter(const kal_uint32 *parameter, const kal_uint32 array_size, const kal_uint32 val) { if (val < array_size) { return parameter[val]; } else { pr_notice("Can't find the parameter \r\n"); return parameter[0]; } } kal_uint32 charging_parameter_to_value(const kal_uint32 *parameter, const kal_uint32 array_size, const kal_uint32 val) { kal_uint32 i; pr_notice("array_size = %d \r\n", array_size); for(i=0;i