提示文章写完后目录可以自动生成如何生成可参考右边的帮助文档文章目录一、什么是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);…}