
提示文章寫完后目錄可以自動生成如何生成可參考右邊的幫助文檔文章目錄一、什么是JEITA二、設備樹屬性與代碼分析2.1 設備樹屬性2.2 設備樹屬性初始化2.3 電池溫度與jeita充電電壓的關系代碼分析2.4 電池電壓的設置與寫入一、什么是JEITAJEITAJapan Electronics and Information Technology Industries Association日本電子信息技術產業協會為了提高鋰離子電池充電的安全性JEITA和日本電池協會于2007年4月20日發布了新的安全指南。他們的指導方針著重強調了在某些低溫和高溫范圍內避免高充電電流和高充電電壓的重要性。這個是百度的一些關于jeita的說明從圖中來看總的來說jeita就是對電池溫度做一個多段的細分在不同的溫度段中設置不同的充電電壓和充電電流。具體分析見下面關于jeita的代碼分析。二、設備樹屬性與代碼分析2.1 設備樹屬性先從設備樹中查看jeita相關的屬性設置charger: charger {…/* sw jeita */jeita_temp_above_t4_cv 4240000;jeita_temp_t3_to_t4_cv 4240000;jeita_temp_t2_to_t3_cv 4340000;jeita_temp_t1_to_t2_cv 4240000;jeita_temp_t0_to_t1_cv 4040000;jeita_temp_below_t0_cv 4040000;temp_t4_thres 50;temp_t4_thres_minus_x_degree 47;temp_t3_thres 45;temp_t3_thres_minus_x_degree 39;temp_t2_thres 10;temp_t2_thres_plus_x_degree 16;temp_t1_thres 0;temp_t1_thres_plus_x_degree 6;temp_t0_thres 0;temp_t0_thres_plus_x_degree 0;temp_neg_10_thres 0;…}從這里來看jeita的電壓分為了4個其中從設備樹中這個屬性的設置可以看出還有一些溫度屬性相關的設置2.2 設備樹屬性初始化static int mtk_charger_parse_dt(struct charger_manager *info,struct devicedev){…/enable_sw_jeita;/ //如果要使用jeita相關的功能需要把這個注釋打開/sw jeita *///jeita充電電壓的屬性初始化賦值if (of_property_read_u32(np, “jeita_temp_above_t4_cv”, val) 0)info-data.jeita_temp_above_t4_cv val;else {chr_err(“use default JEITA_TEMP_ABOVE_T4_CV:%d\n”,JEITA_TEMP_ABOVE_T4_CV);info-data.jeita_temp_above_t4_cv JEITA_TEMP_ABOVE_T4_CV;}if (of_property_read_u32(np, jeita_temp_t3_to_t4_cv, val) 0) info-data.jeita_temp_t3_to_t4_cv val; else { chr_err(use default JEITA_TEMP_T3_TO_T4_CV:%d\n, JEITA_TEMP_T3_TO_T4_CV); info-data.jeita_temp_t3_to_t4_cv JEITA_TEMP_T3_TO_T4_CV; } ... //充電溫度段的屬性初始化賦值 if (of_property_read_u32(np, temp_t4_thres, val) 0) info-data.temp_t4_thres val; else { chr_err(use default TEMP_T4_THRES:%d\n, TEMP_T4_THRES); info-data.temp_t4_thres TEMP_T4_THRES; } if (of_property_read_u32(np, temp_t4_thres_minus_x_degree, val) 0) info-data.temp_t4_thres_minus_x_degree val; else { chr_err(use default TEMP_T4_THRES_MINUS_X_DEGREE:%d\n, TEMP_T4_THRES_MINUS_X_DEGREE); info-data.temp_t4_thres_minus_x_degree TEMP_T4_THRES_MINUS_X_DEGREE; } ...…}經過上述初始化設置就可以從設備樹中獲取jeita相關的參數了2.3 電池溫度與jeita充電電壓的關系代碼分析1.會先對jeita.sm進行一個初始化根據電池溫度對jeita.sm進行溫度段的賦值即當前電池溫度屬于jeita中哪一個溫度段具體見如下代碼//根據當前電池溫度對jeita.sm進行初始化void sw_jeita_state_machine_init(struct charger_manager *info){struct sw_jeita_data *sw_jeita;if (info-enable_sw_jeita true) { sw_jeita info-sw_jeita; //獲取當前電池溫度 info-battery_temp battery_get_bat_temperature(); //根據電池溫度對jeita.sm的溫度段進行賦值 if (info-battery_temp info-data.temp_t4_thres) sw_jeita-sm TEMP_ABOVE_T4; else if (info-battery_temp info-data.temp_t3_thres) sw_jeita-sm TEMP_T3_TO_T4; else if (info-battery_temp info-data.temp_t2_thres) sw_jeita-sm TEMP_T2_TO_T3; else if (info-battery_temp info-data.temp_t1_thres) sw_jeita-sm TEMP_T1_TO_T2; else if (info-battery_temp info-data.temp_t0_thres) sw_jeita-sm TEMP_T0_TO_T1; else sw_jeita-sm TEMP_BELOW_T0; chr_err([SW_JEITA] tmp:%d sm:%d\n, info-battery_temp, sw_jeita-sm); }}2.在充電器的線程中如果插入充電器且info-enable_sw_jeita true即打開了jeita的使能設置那么會有如下static int charger_routine_thread(void *arg){…charger_check_status(info);…}static void charger_check_status(struct charger_manager *info){…//這里會對jeita是否使能進行判斷if (info-enable_sw_jeita true) {//這里就是jeita的核心do_sw_jeita_state_machine(info);if (info-sw_jeita.charging false) {charging false;goto stop_charging;}} else {…}…}3.這里會對核心函數do_sw_jeita_state_machine進行分析void do_sw_jeita_state_machine(struct charger_manager *info){struct sw_jeita_data *sw_jeita;sw_jeita info-sw_jeita; sw_jeita-pre_sm sw_jeita-sm; sw_jeita-charging true; /* JEITA battery temp Standard */ // 下面是關于jeita.sm的一些設置jeita.sm會影響jeita.cv的設置下面會有如下幾種設置 // 這里會對這片代碼進行分析 if (info-battery_temp info-data.temp_t4_thres) { chr_err([SW_JEITA] Battery Over high Temperature(%d) !!\n, info-data.temp_t4_thres); //jeita.sm被設置為TEMP_ABOVE_T4 sw_jeita-sm TEMP_ABOVE_T4; //設置停止充電標志false不充 sw_jeita-charging false; } else if (info-battery_temp info-data.temp_t3_thres) { /* control 45 degree to normal behavior */ //電池溫度處于45℃~50℃之間執行下列代碼if else if ((sw_jeita-sm TEMP_ABOVE_T4) (info-battery_temp info-data.temp_t4_thres_minus_x_degree)) { chr_err([SW_JEITA] Battery Temperature between %d and %d,not allow charging yet!!\n, info-data.temp_t4_thres_minus_x_degree, info-data.temp_t4_thres); //如果剛從50℃降溫下來且溫度高于47℃充電標志設置為false即不充 sw_jeita-charging false; } else { chr_err([SW_JEITA] Battery Temperature between %d and %d !!\n, info-data.temp_t3_thres, info-data.temp_t4_thres); //如果溫度不是從50℃降下來是從其他溫度升上去超過了45℃使用TEMP_T3_TO_T4的sm sw_jeita-sm TEMP_T3_TO_T4; } } else if (info-battery_temp info-data.temp_t2_thres) { //電池溫度處于10℃~45℃之間執行下列代碼if else if (((sw_jeita-sm TEMP_T3_TO_T4) (info-battery_temp info-data.temp_t3_thres_minus_x_degree)) || ((sw_jeita-sm TEMP_T1_TO_T2) (info-battery_temp info-data.temp_t2_thres_plus_x_degree))) { //如果剛從從45℃降下來且溫度高于39℃還是使用TEMP_T3_TO_T4的sm //或者溫度是剛從0℃升上來且溫度小于16℃還是使用TEMP_T1_TO_T2的sm //從這個判斷可以看出當電池溫度變化范圍沒有超過閾值還是使用上一個電壓進行充電 chr_err([SW_JEITA] Battery Temperature not recovery to normal temperature charging mode yet!!\n); } else { chr_err([SW_JEITA] Battery Normal Temperature between %d and %d !!\n, info-data.temp_t2_thres, info-data.temp_t3_thres); //排除上述兩類情況后處于10℃~45℃之間的電池溫度都是使用TEMP_T2_TO_T3的sm sw_jeita-sm TEMP_T2_TO_T3; } } else if (info-battery_temp info-data.temp_t1_thres) { //電池處于0℃~10℃之間執行下列if else if ((sw_jeita-sm TEMP_T0_TO_T1 || sw_jeita-sm TEMP_BELOW_T0) (info-battery_temp info-data.temp_t1_thres_plus_x_degree)) { //電池溫度剛從0℃以下升上來且小于6℃ if (sw_jeita-sm TEMP_T0_TO_T1) { //如果已經設置了TEMP_T0_TO_T1的sm這里就不做改動 chr_err([SW_JEITA] Battery Temperature between %d and %d !!\n, info-data.temp_t1_thres_plus_x_degree, info-data.temp_t2_thres); } if (sw_jeita-sm TEMP_BELOW_T0) { //如果是剛從-x℃直接升上來不充電 chr_err([SW_JEITA] Battery Temperature between %d and %d,not allow charging yet!!\n, info-data.temp_t1_thres, info-data.temp_t1_thres_plus_x_degree); sw_jeita-charging false; } } else { //電池溫度處于6℃~10攝氏度之間sm使用TEMP_T1_TO_T2 chr_err([SW_JEITA] Battery Temperature between %d and %d !!\n, info-data.temp_t1_thres, info-data.temp_t2_thres); sw_jeita-sm TEMP_T1_TO_T2; } } else if (info-battery_temp info-data.temp_t0_thres) { //電池處于0℃~10℃之間執行下列if else if ((sw_jeita-sm TEMP_BELOW_T0) (info-battery_temp info-data.temp_t0_thres_plus_x_degree)) { //這個判斷里面就是溫度臨界值0℃的處理就是從-x℃上升到0攝氏度還是不充電 chr_err([SW_JEITA] Battery Temperature between %d and %d,not allow charging yet!!\n, info-data.temp_t0_thres, info-data.temp_t0_thres_plus_x_degree); sw_jeita-charging false; } else { chr_err([SW_JEITA] Battery Temperature between %d and %d !!\n, info-data.temp_t0_thres, info-data.temp_t1_thres); //這個判斷攝氏度大于0攝氏度那么設置TEMP_T0_TO_T1的sm sw_jeita-sm TEMP_T0_TO_T1; } //這部分判斷就是要求電池溫度穩定在0℃以上才會進行TEMP_T0_TO_T1的sm設置 } else { //電池溫度低于0℃停止充電 chr_err([SW_JEITA] Battery below low Temperature(%d) !!\n, info-data.temp_t0_thres); sw_jeita-sm TEMP_BELOW_T0; sw_jeita-charging false; } /** 上述判斷的總結 0℃以下不充電 0~6℃ 使用TEMP_T0_TO_T1充電 6~10℃使用TEMP_T1_TO_T2充電 10~45℃ 情況1 剛從10℃上升且溫度低于16℃使用TEMP_T1_TO_T2充電 情況1 剛從45℃下降且溫度高于39℃使用TEMP_T3_TO_T4充電 其他情況 處于10~45℃使用TEMP_T2_TO_T3充電 45℃~50℃ 情況1 剛從50℃下降且溫度高于47℃不充電 其他情況 處于45℃~50℃使用TEMP_T3_TO_T4充電 高于50℃ 停止充電 */ /* set CV after temperature changed */ /* In normal range, we adjust CV dynamically */ //根據sm設置對應充電電壓 if (sw_jeita-sm ! TEMP_T2_TO_T3) { if (sw_jeita-sm TEMP_ABOVE_T4) sw_jeita-cv info-data.jeita_temp_above_t4_cv; else if (sw_jeita-sm TEMP_T3_TO_T4) sw_jeita-cv info-data.jeita_temp_t3_to_t4_cv; else if (sw_jeita-sm TEMP_T2_TO_T3) sw_jeita-cv 0; else if (sw_jeita-sm TEMP_T1_TO_T2) sw_jeita-cv info-data.jeita_temp_t1_to_t2_cv; else if (sw_jeita-sm TEMP_T0_TO_T1) sw_jeita-cv info-data.jeita_temp_t0_to_t1_cv; else if (sw_jeita-sm TEMP_BELOW_T0) sw_jeita-cv info-data.jeita_temp_below_t0_cv; else sw_jeita-cv info-data.battery_cv; } else { sw_jeita-cv 0; } chr_err([SW_JEITA]preState:%d newState:%d tmp:%d cv:%d\n, sw_jeita-pre_sm, sw_jeita-sm, info-battery_temp, sw_jeita-cv);}分析總結根據上述代碼的分析設置了多段的溫度范圍最終可以做到低溫上升與高溫下降電池電壓不會立刻修改充電電壓會給電池一個適應期等滿足適應期跳出條件才會設置在該區間相對應的電池電壓。2.4 電池電壓的設置與寫入//CC充電狀態CC充電狀態可見之前的充電狀態機分析static int mtk_switch_chr_cc(struct charger_manager *info){…swchg_turn_on_charging(info);…}static void swchg_turn_on_charging(struct charger_manager *info){…swchg_select_cv(info);…}static void swchg_select_cv(struct charger_manager *info){…//注意jeita.cv的變量就在這里被傳入這個在2.3小節的最后那里會根據sm對cv進行賦值charger_dev_set_constant_voltage(info-chg1_dev, info-sw_jeita.cv);…}