插入USB开机

Posted Jarry_le

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了插入USB开机相关的知识,希望对你有一定的参考价值。

客户要求:

1.  3.45以下lk充电

2.  3.45 - 3.6 kernel充电

3.  3.6以上自动开机

-----------------------------------------------------------------------------

\\vendor\\mediatek\\proprietary\\bootable\\bootloader\\lk\\platform\\mt8163\\platform.c

void platform_init(void)

......

#ifdef LK_PROFILING

        time_bat_init = get_timer(0);

#endif

        mt65xx_bat_init();        //Isaac check if it's low battery!!!

......

#ifdef MTK_KERNEL_POWER_OFF_CHARGING

        if (kernel_charging_boot() == 1)        //Isaac judge boot mode

......

\\vendor\\mediatek\\proprietary\\bootable\\bootloader\\lk\\platform\\mt8163\\mt_battery.c

#if defined(CUST_BATTERY_LOWVOL_THRESOLD)        //Isaac no

        #define BATTERY_LOWVOL_THRESOLD CUST_BATTERY_LOWVOL_THRESOLD

#else

        #define BATTERY_LOWVOL_THRESOLD             3450        //3450        Isaac

#endif

void mt65xx_bat_init(void)

  

    kal_int32 bat_vol;

   

    // Low Battery Safety Booting

   

    #if defined(SWCHR_POWER_PATH)

    bat_vol = get_i_sense_volt(1);

    #else

    bat_vol = get_bat_sense_volt(1);

    #endif

    pchr_turn_on_charging(KAL_TRUE);

    //dprintf(CRITICAL, "[mt65xx_bat_init] check VBAT=%d mV with %d mV\\n", bat_vol, BATTERY_LOWVOL_THRESOLD);

        printf("Isaac [mt65xx_bat_init] check VBAT=%d mV with %d mV\\n", bat_vol, BATTERY_LOWVOL_THRESOLD);        //Isaac

    if(g_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT && (upmu_get_pwrkey_deb()==0) )

            dprintf(CRITICAL, "[mt65xx_bat_init] KPOC+PWRKEY => change boot mode\\n");       

   

            g_boot_reason_change = true;

   

    rtc_boot_check(false);

    #ifndef MTK_DISABLE_POWER_ON_OFF_VOLTAGE_LIMITATION        //Isaac no

    #ifndef MTK_BATLOWV_NO_PANEL_ON_EARLY                                //Isaac no

            if (bat_vol < BATTERY_LOWVOL_THRESOLD)

    #else

            if (is_low_battery(bat_vol))

    #endif

   

        if(g_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT && upmu_is_chr_det() == KAL_TRUE)

       

            dprintf(CRITICAL, "[%s] Kernel Low Battery Power Off Charging Mode\\n", __func__);

            g_boot_mode = LOW_POWER_OFF_CHARGING_BOOT;

            #ifndef SWCHR_POWER_PATH

            check_bat_protect_status();        //Isaac LOOP CHARGE!!!

            #endif

            return;

       

        else

       

            dprintf(CRITICAL, "[BATTERY] battery voltage(%dmV) <= CLV ! Can not Boot Linux Kernel !! \\n\\r",bat_vol);

    #ifndef NO_POWER_OFF

            mt6575_power_off();

    #endif           

            while(1)

           

                dprintf(CRITICAL, "If you see the log, please check with RTC power off API\\n\\r");

           

       

   

    #endif

    return;

------------------------------------------------------------

\\vendor\\mediatek\\proprietary\\bootable\\bootloader\\lk\\platform\\mt6580\\platform.c

int kernel_charging_boot(void)

        //Isaac add for low power

        int USB_BOOT_JUDGE = 0;

        int My_bat_volt = get_bat_sense_volt(5);

       

        if(My_bat_volt >=3590)

                g_boot_mode = NORMAL_BOOT;

                USB_BOOT_JUDGE = 1;

       

        printf("Isaac My_bat_volt = %d, USB_BOOT_JUDGE = %d\\n", My_bat_volt, USB_BOOT_JUDGE);

        //Isaac add for low power

        if ((g_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT || g_boot_mode == LOW_POWER_OFF_CHARGING_BOOT) && upmu_is_chr_det() == KAL_TRUE)

                dprintf(INFO,"[%s] Kernel Power Off Charging with Charger/Usb \\n", __func__);

                return  1;

        else if ((g_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT || g_boot_mode == LOW_POWER_OFF_CHARGING_BOOT) && upmu_is_chr_det() == KAL_FALSE)

                dprintf(INFO,"[%s] Kernel Power Off Charging without Charger/Usb \\n", __func__);

                return -1;

        else

                return 0;

\\kernel-3.18\\drivers\\power\\mediatek\\linear_charging.c

#include <mt-plat/mt_boot.h>                //Isaac #include "mt_boot_common.h"

//Isaac add

#include <linux/reboot.h>

//#include <mt-plat/mt_boot_common.h>        //boot_mode_t        get_boot_mode()

//Isaac add

PMU_STATUS BAT_ConstantCurrentModeAction(void)

        battery_log(BAT_LOG_CRTI, "[BATTERY] CC mode charge, timer=%d on %d !!\\n\\r",

                    BMT_status.CC_charging_time, BMT_status.total_charging_time);

        BMT_status.PRE_charging_time = 0;

        BMT_status.CC_charging_time += BAT_TASK_PERIOD;

        BMT_status.TOPOFF_charging_time = 0;

        BMT_status.total_charging_time += BAT_TASK_PERIOD;

        ulc_cv_charging_current_flag = KAL_FALSE;

        ulc_cv_charging_current = g_temp_CC_value;

       

        printk("Isaac [BAT_ConstantCurrentModeAction] check VBAT=%d mVm, get_boot_mode() = %d\\n", BMT_status.bat_vol, get_boot_mode());

        //Isaac add for low power charge

        if ((BMT_status.bat_vol > 3620) && (get_boot_mode() == KERNEL_POWER_OFF_CHARGING_BOOT || get_boot_mode() == LOW_POWER_OFF_CHARGING_BOOT))

                kernel_power_off();

          //battery_charging_control(CHARGING_CMD_SET_POWER_OFF, NULL);

        //Isaac add for low power charge

       

        if (BMT_status.bat_vol > v_cc2topoff_threshold)

                BMT_status.bat_charging_state = CHR_TOP_OFF;

#if defined(CONFIG_MTK_PUMP_EXPRESS_SUPPORT)        /* defined(MTK_LINEAR_CHARGER_NO_DISCHARGE) */

        /* no disable charging#else */

#else

       

                kal_bool charging_enable = KAL_FALSE;

                /* Charging 9s and discharging 1s : start */

                battery_charging_control(CHARGING_CMD_ENABLE, &charging_enable);

                msleep(1000);

       

#endif

        charging_current_calibration();

        pchr_turn_on_charging();

        return PMU_STATUS_OK;

在kernel阶段判断的电压要比lk阶段的启动电压要大,否则kernel充电到3.6自动关机重启后电压只有3.58,lk阶段判断启动电压不满足,继续充电,3.6关机,死循环!!

REFERENCE:

3.45V 以下关机充电 g_boot_mode = LOW_POWER_OFF_CHARGING_BOOT              //9

3.45V 以上关机充电 g_boot_mode = KERNEL_POWER_OFF_CHARGING_BOOT          //8

\\kernel-3.18\\drivers\\misc\\mediatek\\include\\mt-plat\\mt_boot_common.h

/* return boot mode */

unsigned int get_boot_mode(void)

        init_boot_common(__LINE__);

        return g_boot_mode;

\\vendor\\mediatek\\proprietary\\bootable\\bootloader\\lk\\platform\\mt8163\\include\\platform\\boot_mode.h

/* boot type definitions */

typedef enum

    NORMAL_BOOT = 0,

    META_BOOT = 1,

    RECOVERY_BOOT = 2,

    SW_REBOOT = 3,

    FACTORY_BOOT = 4,

    ADVMETA_BOOT = 5,

    ATE_FACTORY_BOOT = 6,

    ALARM_BOOT = 7,

#if defined (MTK_KERNEL_POWER_OFF_CHARGING)

    KERNEL_POWER_OFF_CHARGING_BOOT = 8,

    LOW_POWER_OFF_CHARGING_BOOT = 9,

#endif

    FASTBOOT = 99,

    DOWNLOAD_BOOT = 100,

    UNKNOWN_BOOT

BOOTMODE;

\\kernel-3.18\\drivers\\misc\\mediatek\\include\\mt-plat\\mt_boot_common.h

/* boot type definitions */

enum boot_mode_t

        NORMAL_BOOT = 0,

        META_BOOT = 1,

        RECOVERY_BOOT = 2,

        SW_REBOOT = 3,

        FACTORY_BOOT = 4,

        ADVMETA_BOOT = 5,

        ATE_FACTORY_BOOT = 6,

        ALARM_BOOT = 7,

#if defined(CONFIG_MTK_KERNEL_POWER_OFF_CHARGING)

        KERNEL_POWER_OFF_CHARGING_BOOT = 8,

        LOW_POWER_OFF_CHARGING_BOOT = 9,

#endif

        DONGLE_BOOT = 10,

        UNKNOWN_BOOT

;

/vendor/mediatek/proprietary/bootable/bootloader/lk/platform/mt8163/mt_pmic_mt6323.c

int get_bat_sense_volt(int times)

    return PMIC_IMM_GetOneChannelValue(VBAT_CHANNEL_NUMBER,times,1);

int get_i_sense_volt(int times)

    return PMIC_IMM_GetOneChannelValue(ISENSE_CHANNEL_NUMBER,times,1);

int get_charger_volt(int times)

    return PMIC_IMM_GetOneChannelValue(VCHARGER_CHANNEL_NUMBER,times,1);

int get_tbat_volt(int times)

    return PMIC_IMM_GetOneChannelValue(VBATTEMP_CHANNEL_NUMBER,times,1);

————————————————
版权声明:本文为CSDN博主「0_0i_i」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/chylovecsd/article/details/125349862

以上是关于插入USB开机的主要内容,如果未能解决你的问题,请参考以下文章

openwrt开机usb要插拔

利用Java语言,实现数组的排序

从其他语言(如 Java、PHP、Perl、Python 等)调用 C/C++ 代码的最佳方法是啥?

macbook air 插入USB无线网卡怎么没反应

如何利用C语言,C++语言打开USB串口,然後对其发送信号? 跪求回答! 可行比加分!!

五分钟了解 Service Mesh