1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774 |
- #include "sec_battery.h"
- #define STEP_CHARGING_CONDITION_VOLTAGE 0x01
- #define STEP_CHARGING_CONDITION_SOC 0x02
- #define STEP_CHARGING_CONDITION_CHARGE_POWER 0x04
- #define STEP_CHARGING_CONDITION_ONLINE 0x08
- #define STEP_CHARGING_CONDITION_CURRENT_NOW 0x10
- #define STEP_CHARGING_CONDITION_FLOAT_VOLTAGE 0x20
- #define STEP_CHARGING_CONDITION_INPUT_CURRENT 0x40
- #define STEP_CHARGING_CONDITION_SOC_INIT_ONLY 0x80
- #define STEP_CHARGING_CONDITION_FORCE_SOC 0x100
- #define STEP_CHARGING_CONDITION_FG_CURRENT 0x200
- #define STEP_CHARGING_CONDITION_DC_INIT (STEP_CHARGING_CONDITION_VOLTAGE | STEP_CHARGING_CONDITION_SOC | STEP_CHARGING_CONDITION_SOC_INIT_ONLY)
- #define DIRECT_CHARGING_FLOAT_VOLTAGE_MARGIN 20
- #define DIRECT_CHARGING_FORCE_SOC_MARGIN 10
- void sec_bat_reset_step_charging(struct sec_battery_info *battery)
- {
- pr_info("%s\n", __func__);
- battery->step_chg_status = -1;
- #if IS_ENABLED(CONFIG_WIRELESS_CHARGING)
- battery->wpc_step_chg_status = -1;
- #endif
- #if IS_ENABLED(CONFIG_DIRECT_CHARGING)
- battery->dc_float_voltage_set = false;
- #endif
- }
- EXPORT_SYMBOL(sec_bat_reset_step_charging);
- void sec_bat_exit_step_charging(struct sec_battery_info *battery)
- {
- sec_vote(battery->fcc_vote, VOTER_STEP_CHARGE, false, 0);
- if (battery->step_chg_type & STEP_CHARGING_CONDITION_FLOAT_VOLTAGE)
- sec_vote(battery->fv_vote, VOTER_STEP_CHARGE, false, 0);
- sec_bat_reset_step_charging(battery);
- }
- EXPORT_SYMBOL(sec_bat_exit_step_charging);
- void sec_bat_exit_wpc_step_charging(struct sec_battery_info *battery)
- {
- sec_vote(battery->fcc_vote, VOTER_WPC_STEP_CHARGE, false, 0);
- if (battery->step_chg_type & STEP_CHARGING_CONDITION_FLOAT_VOLTAGE)
- sec_vote(battery->fv_vote, VOTER_WPC_STEP_CHARGE, false, 0);
- sec_bat_reset_step_charging(battery);
- }
- EXPORT_SYMBOL(sec_bat_exit_wpc_step_charging);
- bool sec_bat_check_step_charging(struct sec_battery_info *battery)
- {
- int i = 0, value = 0, step_condition = 0, lcd_status = 0;
- #if IS_ENABLED(CONFIG_DUAL_BATTERY)
- int value_sub = 0, step_condition_sub = 0;
- #endif
- static int curr_cnt;
- static bool skip_lcd_on_changed;
- int age_step = battery->pdata->age_step;
- union power_supply_propval val = {0, };
- int fpdo_sc = 0;
- #if IS_ENABLED(CONFIG_WIRELESS_CHARGING)
- if (is_wireless_all_type(battery->cable_type)) {
- sec_vote(battery->fv_vote, VOTER_STEP_CHARGE, false, 0);
- sec_vote(battery->fcc_vote, VOTER_STEP_CHARGE, false, 0);
- return false;
- }
- #endif
- #if defined(CONFIG_SEC_FACTORY)
- if (!battery->step_chg_en_in_factory)
- return false;
- #endif
- if (!battery->step_chg_type)
- return false;
- #if defined(CONFIG_ENG_BATTERY_CONCEPT)
- if (battery->test_charge_current)
- return false;
- if (battery->test_step_condition <= 4500)
- battery->pdata->step_chg_cond[0][0] = battery->test_step_condition;
- #endif
- if (battery->siop_level < 100 || battery->lcd_status)
- lcd_status = 1;
- else
- lcd_status = 0;
- if (battery->cable_type == SEC_BATTERY_CABLE_FPDO_DC) {
- psy_do_property(battery->pdata->charger_name, get,
- POWER_SUPPLY_EXT_PROP_CHARGING_ENABLED_DC, val);
- fpdo_sc = val.intval;
- pr_info("%s: SC for FPDO_DC(%d)", __func__, fpdo_sc);
- if (!fpdo_sc && battery->step_chg_status >= 0)
- sec_bat_reset_step_charging(battery);
- }
- if (battery->step_chg_type & STEP_CHARGING_CONDITION_ONLINE) {
- #if IS_ENABLED(CONFIG_DIRECT_CHARGING)
- if ((is_pd_apdo_wire_type(battery->cable_type) && !fpdo_sc) &&
- !((battery->current_event & SEC_BAT_CURRENT_EVENT_DC_ERR) &&
- (battery->ta_alert_mode == OCP_NONE))) {
- sec_vote(battery->fv_vote, VOTER_STEP_CHARGE, false, 0);
- sec_vote(battery->fcc_vote, VOTER_STEP_CHARGE, false, 0);
- return false;
- }
- if (((is_pd_apdo_wire_type(battery->cable_type) || is_pd_apdo_wire_type(battery->wire_status)) &&
- !fpdo_sc) &&
- (battery->sink_status.rp_currentlvl == RP_CURRENT_LEVEL3)) {
- pr_info("%s: This cable type should be checked in dc step check\n", __func__);
- sec_vote(battery->fv_vote, VOTER_STEP_CHARGE, false, 0);
- sec_vote(battery->fcc_vote, VOTER_STEP_CHARGE, false, 0);
- return false;
- }
- #endif
- if (!is_hv_wire_type(battery->cable_type) && !is_pd_wire_type(battery->cable_type) &&
- (battery->sink_status.rp_currentlvl != RP_CURRENT_LEVEL3)) {
- sec_vote(battery->fv_vote, VOTER_STEP_CHARGE, false, 0);
- sec_vote(battery->fcc_vote, VOTER_STEP_CHARGE, false, 0);
- return false;
- }
- }
- pr_info("%s\n", __func__);
- if (battery->step_chg_type & STEP_CHARGING_CONDITION_CHARGE_POWER) {
- if (battery->max_charge_power < battery->step_chg_charge_power) {
-
- sec_bat_exit_step_charging(battery);
- return false;
- }
- }
- if (battery->step_charging_skip_lcd_on && lcd_status) {
- if (!skip_lcd_on_changed) {
- if (battery->step_chg_status != (battery->step_chg_step - 1)) {
- sec_vote(battery->fcc_vote, VOTER_STEP_CHARGE, true,
- battery->pdata->step_chg_curr[age_step][battery->step_chg_step - 1]);
- if (battery->step_chg_type & STEP_CHARGING_CONDITION_FLOAT_VOLTAGE) {
- pr_info("%s : float voltage = %d\n", __func__,
- battery->pdata->step_chg_vfloat[age_step][battery->step_chg_step - 1]);
- sec_vote(battery->fv_vote, VOTER_STEP_CHARGE, true,
- battery->pdata->step_chg_vfloat[age_step][battery->step_chg_step - 1]);
- }
- pr_info("%s : skip step charging because lcd on\n", __func__);
- skip_lcd_on_changed = true;
- return true;
- }
- }
- return false;
- }
- if (battery->step_chg_status < 0) {
- i = 0;
-
- if (battery->step_chg_type & STEP_CHARGING_CONDITION_SOC_INIT_ONLY) {
- int soc_condition;
- value = battery->capacity;
- while (i < battery->step_chg_step - 1) {
- soc_condition = battery->pdata->step_chg_cond_soc[age_step][i];
- if (value < soc_condition)
- break;
- i++;
- }
- pr_info("%s : set initial step(%d) by soc\n", __func__, i);
- goto check_step_change;
- }
- } else
- i = battery->step_chg_status;
- step_condition = battery->pdata->step_chg_cond[age_step][i];
- if (battery->step_chg_type & STEP_CHARGING_CONDITION_VOLTAGE) {
- #if IS_ENABLED(CONFIG_DUAL_BATTERY)
- step_condition_sub = battery->pdata->step_chg_cond_sub[age_step][i];
- value = battery->voltage_avg_main;
- value_sub = battery->voltage_avg_sub;
- #else
- value = battery->voltage_avg;
- #endif
- } else if (battery->step_chg_type & STEP_CHARGING_CONDITION_SOC) {
- value = battery->capacity;
- if (lcd_status) {
- step_condition = battery->pdata->step_chg_cond[age_step][i] + 15;
- curr_cnt = 0;
- }
- } else {
- return false;
- }
- while (i < battery->step_chg_step - 1) {
- #if IS_ENABLED(CONFIG_DUAL_BATTERY)
- if (battery->step_chg_type & STEP_CHARGING_CONDITION_VOLTAGE) {
- if ((value < step_condition) && (value_sub < step_condition_sub))
- break;
- } else {
- if (value < step_condition)
- break;
- }
- #else
- if (value < step_condition)
- break;
- #endif
- i++;
- if ((battery->step_chg_type & STEP_CHARGING_CONDITION_SOC) &&
- lcd_status)
- step_condition = battery->pdata->step_chg_cond[age_step][i] + 15;
- else {
- step_condition = battery->pdata->step_chg_cond[age_step][i];
- #if IS_ENABLED(CONFIG_DUAL_BATTERY)
- if (battery->step_chg_type & STEP_CHARGING_CONDITION_VOLTAGE)
- step_condition_sub = battery->pdata->step_chg_cond_sub[age_step][i];
- #endif
- }
- if (battery->step_chg_status != -1)
- break;
- }
- check_step_change:
- if ((i != battery->step_chg_status) || skip_lcd_on_changed) {
-
- if ((battery->step_chg_type & STEP_CHARGING_CONDITION_CURRENT_NOW) &&
- !lcd_status &&
- battery->step_chg_status >= 0) {
- int condition_curr;
- condition_curr = max(battery->current_avg, battery->current_now);
- if (condition_curr < battery->pdata->step_chg_cond_curr[battery->step_chg_status]) {
- curr_cnt++;
- pr_info("%s : cnt = %d, curr(%d)mA < curr cond(%d)mA\n",
- __func__, curr_cnt, condition_curr,
- battery->pdata->step_chg_cond_curr[battery->step_chg_status]);
- if (curr_cnt < 3)
- return false;
- } else {
- pr_info("%s : clear cnt, curr(%d)mA >= curr cond(%d)mA or < 0mA\n",
- __func__, condition_curr,
- battery->pdata->step_chg_cond_curr[battery->step_chg_status]);
- curr_cnt = 0;
- return false;
- }
- }
- pr_info("%s : prev=%d, new=%d, value=%d, current=%d, curr_cnt=%d\n", __func__,
- battery->step_chg_status, i, value,
- battery->pdata->step_chg_curr[age_step][i], curr_cnt);
- battery->step_chg_status = i;
- skip_lcd_on_changed = false;
- sec_vote(battery->fcc_vote, VOTER_STEP_CHARGE, true,
- battery->pdata->step_chg_curr[age_step][i]);
- if (battery->step_chg_type & STEP_CHARGING_CONDITION_FLOAT_VOLTAGE) {
- pr_info("%s : float voltage = %d\n", __func__,
- battery->pdata->step_chg_vfloat[age_step][i]);
- sec_vote(battery->fv_vote, VOTER_STEP_CHARGE, true,
- battery->pdata->step_chg_vfloat[age_step][i]);
- }
- return true;
- }
- return false;
- }
- EXPORT_SYMBOL(sec_bat_check_step_charging);
- #if IS_ENABLED(CONFIG_WIRELESS_CHARGING)
- bool sec_bat_check_wpc_step_charging(struct sec_battery_info *battery)
- {
- int i = 0, value = 0, step_condition = 0, lcd_status = 0;
- static int curr_cnt;
- static bool skip_lcd_on_changed;
- int age_step = battery->pdata->age_step;
- #if defined(CONFIG_SEC_FACTORY)
- if (!battery->step_chg_en_in_factory)
- return false;
- #endif
- if (!battery->wpc_step_chg_type)
- return false;
- if (is_not_wireless_type(battery->cable_type)) {
- sec_vote(battery->fv_vote, VOTER_WPC_STEP_CHARGE, false, 0);
- sec_vote(battery->fcc_vote, VOTER_WPC_STEP_CHARGE, false, 0);
- return false;
- }
- #if defined(CONFIG_ENG_BATTERY_CONCEPT)
- if (battery->test_charge_current)
- return false;
- if (battery->test_step_condition <= 4500)
- battery->pdata->wpc_step_chg_cond[0][0] = battery->test_step_condition;
- #endif
- if (battery->siop_level < 100 || battery->lcd_status)
- lcd_status = 1;
- else
- lcd_status = 0;
- if (battery->wpc_step_chg_type & STEP_CHARGING_CONDITION_CHARGE_POWER) {
- if (battery->max_charge_power < battery->wpc_step_chg_charge_power) {
-
- sec_bat_exit_wpc_step_charging(battery);
- return false;
- }
- }
- if (battery->step_charging_skip_lcd_on && lcd_status) {
- if (!skip_lcd_on_changed) {
- if (battery->wpc_step_chg_status != (battery->wpc_step_chg_step - 1)) {
- sec_vote(battery->fcc_vote, VOTER_WPC_STEP_CHARGE, true,
- battery->pdata->wpc_step_chg_curr[age_step][battery->wpc_step_chg_step - 1]);
- if (battery->wpc_step_chg_type & STEP_CHARGING_CONDITION_FLOAT_VOLTAGE) {
- pr_info("%s : float voltage = %d\n", __func__,
- battery->pdata->wpc_step_chg_vfloat[age_step][battery->wpc_step_chg_step - 1]);
- sec_vote(battery->fv_vote, VOTER_WPC_STEP_CHARGE, true,
- battery->pdata->wpc_step_chg_vfloat[age_step][battery->wpc_step_chg_step - 1]);
- }
- pr_info("%s : skip step charging because lcd on\n", __func__);
- skip_lcd_on_changed = true;
- return true;
- }
- }
- return false;
- }
- if (battery->wpc_step_chg_status < 0)
- i = 0;
- else
- i = battery->wpc_step_chg_status;
- step_condition = battery->pdata->wpc_step_chg_cond[age_step][i];
- if (battery->wpc_step_chg_type & STEP_CHARGING_CONDITION_VOLTAGE) {
- value = battery->voltage_avg;
- } else if (battery->wpc_step_chg_type & STEP_CHARGING_CONDITION_SOC) {
- value = battery->capacity;
- if (lcd_status) {
- step_condition = battery->pdata->wpc_step_chg_cond[age_step][i] + 15;
- curr_cnt = 0;
- }
- } else {
- return false;
- }
- while (i < battery->wpc_step_chg_step - 1) {
- if (value < step_condition)
- break;
- i++;
- if ((battery->wpc_step_chg_type & STEP_CHARGING_CONDITION_SOC) &&
- lcd_status)
- step_condition = battery->pdata->wpc_step_chg_cond[age_step][i] + 15;
- else {
- step_condition = battery->pdata->wpc_step_chg_cond[age_step][i];
- }
- if (battery->wpc_step_chg_status != -1)
- break;
- }
-
- if ((battery->wpc_step_chg_type & STEP_CHARGING_CONDITION_CURRENT_NOW) &&
- !lcd_status &&
- battery->wpc_step_chg_status >= 0) {
- int condition_curr;
- condition_curr = max(battery->current_avg, battery->current_now);
- if (condition_curr < battery->pdata->wpc_step_chg_cond_curr[battery->wpc_step_chg_status]) {
- curr_cnt++;
- pr_info("%s : cnt = %d, curr(%d)mA < curr cond(%d)mA\n",
- __func__, curr_cnt, condition_curr,
- battery->pdata->wpc_step_chg_cond_curr[battery->wpc_step_chg_status]);
- if (curr_cnt < 3)
- return false;
- } else {
- pr_info("%s : clear cnt, curr(%d)mA >= curr cond(%d)mA or < 0mA\n",
- __func__, condition_curr,
- battery->pdata->wpc_step_chg_cond_curr[battery->wpc_step_chg_status]);
- curr_cnt = 0;
- return false;
- }
- }
- pr_info("%s : prev=%d, new=%d, value=%d, current=%d, curr_cnt=%d\n", __func__,
- battery->wpc_step_chg_status, i, value,
- battery->pdata->wpc_step_chg_curr[age_step][i], curr_cnt);
- battery->wpc_step_chg_status = i;
- skip_lcd_on_changed = false;
- sec_vote(battery->fcc_vote, VOTER_WPC_STEP_CHARGE, true,
- battery->pdata->wpc_step_chg_curr[age_step][i]);
- if (battery->wpc_step_chg_type & STEP_CHARGING_CONDITION_FLOAT_VOLTAGE) {
- pr_info("%s : float voltage = %d\n", __func__,
- battery->pdata->wpc_step_chg_vfloat[age_step][i]);
- sec_vote(battery->fv_vote, VOTER_WPC_STEP_CHARGE, true,
- battery->pdata->wpc_step_chg_vfloat[age_step][i]);
- }
- return true;
- }
- EXPORT_SYMBOL(sec_bat_check_wpc_step_charging);
- #endif
- #if IS_ENABLED(CONFIG_DIRECT_CHARGING)
- bool skip_check_dc_step(struct sec_battery_info *battery)
- {
- if (battery->dchg_dc_in_swelling) {
- if (battery->current_event & SEC_BAT_CURRENT_EVENT_LOW_TEMP_MODE)
- return true;
- } else {
- if (battery->current_event & SEC_BAT_CURRENT_EVENT_SWELLING_MODE)
- return true;
- }
- if (battery->current_event & SEC_BAT_CURRENT_EVENT_HV_DISABLE ||
- ((battery->current_event & SEC_BAT_CURRENT_EVENT_DC_ERR) &&
- (battery->ta_alert_mode == OCP_NONE)) ||
- battery->current_event & SEC_BAT_CURRENT_EVENT_SIOP_LIMIT ||
- battery->wc_tx_enable ||
- battery->uno_en ||
- battery->mix_limit ||
- battery->lrp_chg_src == SEC_CHARGING_SOURCE_SWITCHING)
- return true;
- else
- return false;
- }
- bool sec_bat_check_dc_step_charging(struct sec_battery_info *battery)
- {
- int i, value;
- int step = -1, step_vol = -1, step_input = -1, step_soc = -1, soc_condition = 0;
- int force_step_soc = 0, step_fg_current = -1;
- bool force_change_step = false;
- union power_supply_propval val = {0, };
- int age_step = battery->pdata->age_step;
- unsigned int dc_step_chg_type;
- if (battery->cable_type == SEC_BATTERY_CABLE_FPDO_DC) {
- sec_vote(battery->dc_fv_vote, VOTER_DC_STEP_CHARGE, false, 0);
- sec_vote(battery->fcc_vote, VOTER_CABLE, true,
- battery->pdata->charging_current[SEC_BATTERY_CABLE_FPDO_DC].fast_charging_current);
- sec_vote_refresh(battery->fcc_vote);
- return false;
- }
- i = (battery->step_chg_status < 0 ? 0 : battery->step_chg_status);
- dc_step_chg_type = battery->dc_step_chg_type[i];
- if (!dc_step_chg_type) {
- sec_vote(battery->dc_fv_vote, VOTER_DC_STEP_CHARGE, false, 0);
- return false;
- }
- if (dc_step_chg_type & STEP_CHARGING_CONDITION_CHARGE_POWER)
- if (battery->charge_power < battery->dc_step_chg_charge_power) {
- sec_vote(battery->dc_fv_vote, VOTER_DC_STEP_CHARGE, false, 0);
- return false;
- }
- if (dc_step_chg_type & STEP_CHARGING_CONDITION_ONLINE) {
- if (!is_pd_apdo_wire_type(battery->cable_type)) {
- sec_vote(battery->dc_fv_vote, VOTER_DC_STEP_CHARGE, false, 0);
- return false;
- }
- }
- if (skip_check_dc_step(battery)) {
- if (battery->step_chg_status >= 0)
- sec_bat_reset_step_charging(battery);
- sec_vote(battery->dc_fv_vote, VOTER_DC_STEP_CHARGE, false, 0);
- return false;
- }
- if (!(dc_step_chg_type & STEP_CHARGING_CONDITION_DC_INIT)) {
- pr_info("%s : cond_vol and cond_soc are both empty\n", __func__);
- sec_vote(battery->dc_fv_vote, VOTER_DC_STEP_CHARGE, false, 0);
- return false;
- }
-
- if (dc_step_chg_type & STEP_CHARGING_CONDITION_SOC_INIT_ONLY) {
- if (battery->step_chg_status < 0) {
- step_soc = i;
- value = battery->capacity;
- while (step_soc < battery->dc_step_chg_step - 1) {
- soc_condition = battery->pdata->dc_step_chg_cond_soc[age_step][step_soc];
- if (value < soc_condition)
- break;
- step_soc++;
- }
- if ((step_soc < step) || (step < 0))
- step = step_soc;
- pr_info("%s : set initial step(%d) by soc\n", __func__, step_soc);
- goto check_dc_step_change;
- } else
- step_soc = battery->dc_step_chg_step - 1;
- }
- if (dc_step_chg_type & STEP_CHARGING_CONDITION_SOC) {
- step_soc = i;
- value = battery->capacity;
- while (step_soc < battery->dc_step_chg_step - 1) {
- soc_condition = battery->pdata->dc_step_chg_cond_soc[age_step][step_soc];
- if (battery->step_chg_status >= 0 &&
- (battery->siop_level < 100 || battery->lcd_status)) {
- soc_condition += DIRECT_CHARGING_FORCE_SOC_MARGIN;
- force_change_step = true;
- }
- if (value < soc_condition)
- break;
- step_soc++;
- if (battery->step_chg_status >= 0)
- break;
- }
- if ((step_soc < step) || (step < 0))
- step = step_soc;
- if (battery->step_chg_status < 0) {
- pr_info("%s : set initial step(%d) by soc\n", __func__, step_soc);
- goto check_dc_step_change;
- }
- if (force_change_step) {
- pr_info("%s : force check step(%d) by soc\n", __func__, step_soc);
- step_vol = step_input = step_soc;
- battery->dc_step_chg_iin_cnt = battery->pdata->dc_step_chg_iin_check_cnt;
- goto check_dc_step_change;
- }
- } else
- step_soc = battery->dc_step_chg_step - 1;
- if (dc_step_chg_type & STEP_CHARGING_CONDITION_VOLTAGE) {
- step_vol = i;
- #if IS_ENABLED(CONFIG_DUAL_BATTERY)
- value = max((battery->voltage_avg_main - battery->pdata->dc_step_cond_v_margin_main),
- (battery->voltage_avg_sub - battery->pdata->dc_step_cond_v_margin_sub));
-
- while (step_vol < battery->dc_step_chg_step - 1) {
- if (battery->voltage_avg_main < battery->pdata->dc_step_chg_cond_vol[age_step][step_vol] &&
- battery->voltage_avg_sub < battery->pdata->dc_step_chg_cond_vol_sub[age_step][step_vol])
- break;
- step_vol++;
- if (battery->step_chg_status >= 0)
- break;
- }
- #else
- if (dc_step_chg_type & STEP_CHARGING_CONDITION_FLOAT_VOLTAGE)
- value = battery->voltage_now + battery->pdata->dc_step_chg_cond_v_margin;
- else
- value = battery->voltage_avg;
- while (step_vol < battery->dc_step_chg_step - 1) {
- if (value < battery->pdata->dc_step_chg_cond_vol[age_step][step_vol])
- break;
- step_vol++;
- if (battery->step_chg_status >= 0)
- break;
- }
- #endif
- if ((step_vol < step) || (step < 0))
- step = step_vol;
- if (battery->step_chg_status < 0) {
- pr_info("%s : set initial step(%d) by vol\n", __func__, step_vol);
- goto check_dc_step_change;
- }
- } else
- step_vol = battery->dc_step_chg_step - 1;
- if (dc_step_chg_type & STEP_CHARGING_CONDITION_INPUT_CURRENT) {
- step_input = i;
- psy_do_property(battery->pdata->charger_name, get,
- POWER_SUPPLY_EXT_PROP_DIRECT_CHARGER_MODE, val);
- if (val.intval != SEC_DIRECT_CHG_MODE_DIRECT_ON) {
- pr_info("%s : dc no charging status = %d\n", __func__, val.intval);
- battery->dc_step_chg_iin_cnt = 0;
- return false;
- } else if (battery->siop_level >= 100 && !battery->lcd_status) {
- val.intval = SEC_BATTERY_IIN_MA;
- psy_do_property(battery->pdata->charger_name, get,
- POWER_SUPPLY_EXT_PROP_MEASURE_INPUT, val);
- value = val.intval;
- while (step_input < battery->dc_step_chg_step - 1) {
- if (value > battery->pdata->dc_step_chg_cond_iin[step_input])
- break;
- step_input++;
- if (battery->step_chg_status >= 0) {
- battery->dc_step_chg_iin_cnt++;
- break;
- } else {
- battery->dc_step_chg_iin_cnt = 0;
- }
- }
- } else {
-
- step_input = battery->dc_step_chg_step - 1;
- }
- if ((step_input < step) || (step < 0))
- step = step_input;
- } else
- step_input = battery->dc_step_chg_step - 1;
- if (dc_step_chg_type & STEP_CHARGING_CONDITION_FG_CURRENT) {
- step_fg_current = i;
- psy_do_property(battery->pdata->charger_name, get,
- POWER_SUPPLY_EXT_PROP_DIRECT_CHARGER_MODE, val);
- if (val.intval != SEC_DIRECT_CHG_MODE_DIRECT_ON) {
- pr_info("%s : dc no charging status = %d\n", __func__, val.intval);
- battery->dc_step_chg_iin_cnt = 0;
- return false;
- } else if (battery->siop_level >= 100 && !battery->lcd_status) {
- int current_now, current_avg;
- val.intval = SEC_BATTERY_CURRENT_MA;
- psy_do_property(battery->pdata->fuelgauge_name, get,
- POWER_SUPPLY_PROP_CURRENT_NOW, val);
- current_now = val.intval;
- val.intval = SEC_BATTERY_CURRENT_MA;
- psy_do_property(battery->pdata->fuelgauge_name, get,
- POWER_SUPPLY_PROP_CURRENT_AVG, val);
- current_avg = val.intval;
- value = max(current_now, current_avg) / 2;
- while (step_fg_current < battery->dc_step_chg_step - 1) {
- if (value > battery->pdata->dc_step_chg_cond_iin[step_fg_current])
- break;
- step_fg_current++;
- if (battery->step_chg_status >= 0) {
- battery->dc_step_chg_iin_cnt++;
- break;
- }
- battery->dc_step_chg_iin_cnt = 0;
- }
- } else {
-
- step_fg_current = battery->dc_step_chg_step - 1;
- }
- if ((step_fg_current < step) || (step < 0))
- step = step_fg_current;
- } else
- step_fg_current = battery->dc_step_chg_step - 1;
- if (dc_step_chg_type & STEP_CHARGING_CONDITION_FORCE_SOC) {
- force_step_soc = i;
- if (battery->capacity >= battery->pdata->dc_step_chg_cond_soc[age_step][i]) {
- if (++force_step_soc > step)
- step = force_step_soc;
- pr_info("%s : SOC(%d) cond_soc(%d) step(%d) force_step_soc(%d)\n", __func__,
- battery->capacity, battery->pdata->dc_step_chg_cond_soc[age_step][i],
- step, force_step_soc);
- } else
- force_step_soc = 0;
- } else
- force_step_soc = 0;
- check_dc_step_change:
- pr_info("%s : curr_step(%d), step_vol(%d), step_soc(%d), step_input(%d, %d), curr_cnt(%d/%d) force_step_soc(%d)\n",
- __func__, step, step_vol, step_soc, step_input, step_fg_current,
- battery->dc_step_chg_iin_cnt, battery->pdata->dc_step_chg_iin_check_cnt, force_step_soc);
- if (battery->step_chg_status < 0 || force_step_soc ||
- (step != battery->step_chg_status &&
- step == min(min(step_vol, step_soc), min(step_input, step_fg_current)))) {
- if ((dc_step_chg_type &
- (STEP_CHARGING_CONDITION_INPUT_CURRENT | STEP_CHARGING_CONDITION_FG_CURRENT)) &&
- (battery->step_chg_status >= 0)) {
- if ((battery->dc_step_chg_iin_cnt < battery->pdata->dc_step_chg_iin_check_cnt) &&
- (battery->siop_level >= 100 && !battery->lcd_status) && !force_step_soc) {
- pr_info("%s : keep step(%d), curr_cnt(%d/%d)\n",
- __func__, battery->step_chg_status,
- battery->dc_step_chg_iin_cnt, battery->pdata->dc_step_chg_iin_check_cnt);
- return false;
- }
- }
- pr_info("%s : cable(%d), soc(%d), step changed(%d->%d), current(%dmA) force_step_soc(%d)\n",
- __func__, battery->cable_type, battery->capacity, battery->step_chg_status, step,
- battery->pdata->dc_step_chg_val_iout[age_step][step], force_step_soc);
-
- battery->pdata->charging_current[battery->cable_type].fast_charging_current =
- battery->pdata->dc_step_chg_val_iout[age_step][step];
- if (dc_step_chg_type & STEP_CHARGING_CONDITION_FLOAT_VOLTAGE) {
- if (battery->step_chg_status < 0) {
- pr_info("%s : step float voltage = %d\n", __func__,
- battery->pdata->dc_step_chg_val_vfloat[age_step][step]);
- sec_vote(battery->dc_fv_vote, VOTER_DC_STEP_CHARGE, true,
- battery->pdata->dc_step_chg_val_vfloat[age_step][step]);
- }
- battery->dc_float_voltage_set = true;
- }
- if (battery->step_chg_status < 0) {
- pr_info("%s : step input current = %d\n", __func__,
- battery->pdata->dc_step_chg_val_iout[age_step][step] / 2);
- val.intval = battery->pdata->dc_step_chg_val_iout[age_step][step] / 2;
- psy_do_property(battery->pdata->charger_name, set,
- POWER_SUPPLY_EXT_PROP_DIRECT_CURRENT_MAX, val);
- }
- battery->step_chg_status = step;
- battery->dc_step_chg_iin_cnt = 0;
- sec_vote(battery->fcc_vote, VOTER_CABLE, true,
- battery->pdata->dc_step_chg_val_iout[age_step][step]);
- sec_vote_refresh(battery->fcc_vote);
- return true;
- } else {
- battery->dc_step_chg_iin_cnt = 0;
- }
- return false;
- }
- EXPORT_SYMBOL(sec_bat_check_dc_step_charging);
- int sec_dc_step_charging_dt(struct sec_battery_info *battery, struct device *dev)
- {
- struct device_node *np = dev->of_node;
- int ret = 0, len = 0;
- sec_battery_platform_data_t *pdata = battery->pdata;
- unsigned int i = 0, j = 0, dc_step_chg_type = 0;
- const u32 *p;
- char str[128] = {0,};
- u32 *soc_cond_temp, *vol_cond_temp, *vfloat_temp, *iout_temp;
- int age_step = battery->pdata->age_step;
- int num_age_step = battery->pdata->num_age_step;
- battery->dchg_dc_in_swelling = of_property_read_bool(np,
- "battery,dchg_dc_in_swelling");
- pr_info("%s: dchg_dc_in_swelling(%d)\n", __func__, battery->dchg_dc_in_swelling);
- ret = of_property_read_u32(np, "battery,dc_step_chg_step",
- &battery->dc_step_chg_step);
- if (ret) {
- pr_err("%s: dc_step_chg_step is Empty\n", __func__);
- battery->dc_step_chg_step = 0;
- goto dc_step_charging_dt_error;
- } else {
- pr_err("%s: dc_step_chg_step is %d\n",
- __func__, battery->dc_step_chg_step);
- }
- battery->dc_step_chg_type = kcalloc(battery->dc_step_chg_step, sizeof(u32), GFP_KERNEL);
- p = of_get_property(np, "battery,dc_step_chg_type", &len);
- if (!p) {
- pr_info("%s: dc_step_chg_type is Empty\n", __func__);
- return -1;
- }
- len = len / sizeof(u32);
- ret = of_property_read_u32_array(np, "battery,dc_step_chg_type",
- battery->dc_step_chg_type, len);
- if (len != battery->dc_step_chg_step) {
- pr_err("%s not match size of dc_step_chg_type: %d\n", __func__, len);
- for (i = 1; i < battery->dc_step_chg_step; i++)
- battery->dc_step_chg_type[i] = battery->dc_step_chg_type[0];
- dc_step_chg_type = battery->dc_step_chg_type[0];
- } else {
- for (i = 0; i < battery->dc_step_chg_step; i++)
- dc_step_chg_type |= battery->dc_step_chg_type[i];
- }
- memset(str, 0x0, sizeof(str));
- sprintf(str + strlen(str), "dc_step_chg_type arr :");
- for (i = 0; i < battery->dc_step_chg_step; i++)
- sprintf(str + strlen(str), " 0x%x", battery->dc_step_chg_type[i]);
- pr_info("%s: %s 0x%x\n", __func__, str, dc_step_chg_type);
- ret = of_property_read_u32(np, "battery,dc_step_chg_charge_power",
- &battery->dc_step_chg_charge_power);
- if (ret) {
- pr_err("%s: dc_step_chg_charge_power is Empty\n", __func__);
- battery->dc_step_chg_charge_power = 20000;
- }
- if (dc_step_chg_type & STEP_CHARGING_CONDITION_VOLTAGE) {
- p = of_get_property(np, "battery,dc_step_chg_cond_vol", &len);
- if (!p) {
- pr_err("%s: dc_step_chg_cond_vol is Empty, type(0x%X->0x%X)\n",
- __func__, dc_step_chg_type,
- dc_step_chg_type & ~STEP_CHARGING_CONDITION_VOLTAGE);
- for (i = 0; i < battery->dc_step_chg_step; i++)
- battery->dc_step_chg_type[i] &= ~STEP_CHARGING_CONDITION_VOLTAGE;
- } else {
- len = len / sizeof(u32);
- pr_info("%s: step(%d) * age_step(%d), dc_step_chg_cond_vol len(%d)\n",
- __func__, battery->dc_step_chg_step, num_age_step, len);
- vol_cond_temp = kcalloc(battery->dc_step_chg_step * num_age_step, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,dc_step_chg_cond_vol",
- vol_cond_temp, battery->dc_step_chg_step * num_age_step);
-
- pdata->dc_step_chg_cond_vol = kcalloc(num_age_step, sizeof(u32 *), GFP_KERNEL);
- for (i = 0; i < num_age_step; i++) {
- pdata->dc_step_chg_cond_vol[i] =
- kcalloc(battery->dc_step_chg_step, sizeof(u32), GFP_KERNEL);
- for (j = 0; j < battery->dc_step_chg_step; j++)
- pdata->dc_step_chg_cond_vol[i][j] =
- vol_cond_temp[i*battery->dc_step_chg_step + j];
- }
-
- if (battery->dc_step_chg_step * num_age_step != len) {
- pr_err("%s: len of dc_step_chg_cond_vol is not matched\n", __func__);
- ret = of_property_read_u32_array(np, "battery,dc_step_chg_cond_vol",
- *pdata->dc_step_chg_cond_vol, battery->dc_step_chg_step);
- for (i = 1; i < num_age_step; i++) {
- for (j = 0; j < battery->dc_step_chg_step; j++)
- pdata->dc_step_chg_cond_vol[i][j] =
- pdata->dc_step_chg_cond_vol[0][j];
- }
- }
-
- for (i = 0; i < num_age_step; i++) {
- memset(str, 0x0, sizeof(str));
- sprintf(str + strlen(str), "vol arr[%d]:", i);
- for (j = 0; j < battery->dc_step_chg_step; j++)
- sprintf(str + strlen(str), " %d", pdata->dc_step_chg_cond_vol[i][j]);
- pr_info("%s: %s\n", __func__, str);
- }
- #if IS_ENABLED(CONFIG_DUAL_BATTERY)
- len = len / sizeof(u32);
- pr_info("%s: step(%d) * age_step(%d), dc_step_chg_cond_vol_sub len(%d)\n",
- __func__, battery->dc_step_chg_step, num_age_step, len);
- vol_cond_temp = kcalloc(battery->dc_step_chg_step * num_age_step, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,dc_step_chg_cond_vol_sub",
- vol_cond_temp, battery->dc_step_chg_step * num_age_step);
-
- pdata->dc_step_chg_cond_vol_sub = kcalloc(num_age_step, sizeof(u32 *), GFP_KERNEL);
- for (i = 0; i < num_age_step; i++) {
- pdata->dc_step_chg_cond_vol_sub[i] =
- kcalloc(battery->dc_step_chg_step, sizeof(u32), GFP_KERNEL);
- for (j = 0; j < battery->dc_step_chg_step; j++)
- pdata->dc_step_chg_cond_vol_sub[i][j] =
- vol_cond_temp[i*battery->dc_step_chg_step + j];
- }
-
- if (battery->dc_step_chg_step * num_age_step != len) {
- pr_err("%s: len of dc_step_chg_cond_vol_sub is not matched\n", __func__);
- ret = of_property_read_u32_array(np, "battery,dc_step_chg_cond_vol_sub",
- *pdata->dc_step_chg_cond_vol_sub, battery->dc_step_chg_step);
- for (i = 1; i < num_age_step; i++) {
- for (j = 0; j < battery->dc_step_chg_step; j++)
- pdata->dc_step_chg_cond_vol_sub[i][j] =
- pdata->dc_step_chg_cond_vol_sub[0][j];
- }
- }
-
- for (i = 0; i < num_age_step; i++) {
- memset(str, 0x0, sizeof(str));
- sprintf(str + strlen(str), "vol_sub arr[%d]:", i);
- for (j = 0; j < battery->dc_step_chg_step; j++)
- sprintf(str + strlen(str), " %d", pdata->dc_step_chg_cond_vol_sub[i][j]);
- pr_info("%s: %s\n", __func__, str);
- }
- #endif
- if (ret) {
- pr_info("%s : dc_step_chg_cond_vol read fail\n", __func__);
- for (i = 0; i < battery->dc_step_chg_step; i++)
- battery->dc_step_chg_type[i] &= ~STEP_CHARGING_CONDITION_VOLTAGE;
- }
- kfree(vol_cond_temp);
- #if IS_ENABLED(CONFIG_DUAL_BATTERY)
- ret = of_property_read_u32(np, "battery,dc_step_cond_v_margin_main",
- &battery->pdata->dc_step_cond_v_margin_main);
- if (ret)
- battery->pdata->dc_step_cond_v_margin_main = 0;
- ret = of_property_read_u32(np, "battery,dc_step_cond_v_margin_sub",
- &battery->pdata->dc_step_cond_v_margin_sub);
- if (ret)
- battery->pdata->dc_step_cond_v_margin_sub = 0;
- ret = of_property_read_u32(np, "battery,sc_vbat_thresh_main",
- &battery->pdata->sc_vbat_thresh_main);
- if (ret)
- battery->pdata->sc_vbat_thresh_main = 4420;
- ret = of_property_read_u32(np, "battery,sc_vbat_thresh_sub",
- &battery->pdata->sc_vbat_thresh_sub);
- if (ret)
- battery->pdata->sc_vbat_thresh_sub = battery->pdata->sc_vbat_thresh_main;
- #endif
- }
- }
- if (dc_step_chg_type & STEP_CHARGING_CONDITION_SOC ||
- dc_step_chg_type & STEP_CHARGING_CONDITION_SOC_INIT_ONLY) {
- p = of_get_property(np, "battery,dc_step_chg_cond_soc", &len);
- if (!p) {
- pr_err("%s: dc_step_chg_cond_soc is Empty, type(0x%X->0x%x)\n",
- __func__, dc_step_chg_type,
- dc_step_chg_type & ~(STEP_CHARGING_CONDITION_SOC |
- STEP_CHARGING_CONDITION_SOC_INIT_ONLY));
- for (i = 0; i < battery->dc_step_chg_step; i++)
- battery->dc_step_chg_type[i] &= ~(STEP_CHARGING_CONDITION_SOC |
- STEP_CHARGING_CONDITION_SOC_INIT_ONLY);
- } else {
- len = len / sizeof(u32);
- pr_info("%s: step(%d) * age_step(%d), dc_step_chg_cond_soc len(%d)\n",
- __func__, battery->dc_step_chg_step, num_age_step, len);
-
- soc_cond_temp = kcalloc(battery->dc_step_chg_step * num_age_step, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,dc_step_chg_cond_soc",
- soc_cond_temp, battery->dc_step_chg_step * num_age_step);
-
- pdata->dc_step_chg_cond_soc = kcalloc(num_age_step, sizeof(u32 *), GFP_KERNEL);
- for (i = 0; i < num_age_step; i++) {
- pdata->dc_step_chg_cond_soc[i] =
- kcalloc(battery->dc_step_chg_step, sizeof(u32), GFP_KERNEL);
- for (j = 0; j < battery->dc_step_chg_step; j++)
- pdata->dc_step_chg_cond_soc[i][j] = soc_cond_temp[i*battery->dc_step_chg_step + j];
- }
-
- if (battery->dc_step_chg_step * num_age_step != len) {
- pr_err("%s: len of dc_step_chg_cond_soc is not matched\n", __func__);
- ret = of_property_read_u32_array(np, "battery,dc_step_chg_cond_soc",
- *pdata->dc_step_chg_cond_soc, battery->dc_step_chg_step);
- for (i = 1; i < num_age_step; i++) {
- for (j = 0; j < battery->dc_step_chg_step; j++)
- pdata->dc_step_chg_cond_soc[i][j] = pdata->dc_step_chg_cond_soc[0][j];
- }
- }
-
- for (i = 0; i < num_age_step; i++) {
- memset(str, 0x0, sizeof(str));
- sprintf(str + strlen(str), "soc arr[%d]:", i);
- for (j = 0; j < battery->dc_step_chg_step; j++)
- sprintf(str + strlen(str), " %d", pdata->dc_step_chg_cond_soc[i][j]);
- pr_info("%s: %s\n", __func__, str);
- }
- if (ret) {
- pr_info("%s : dc_step_chg_cond_soc read fail\n", __func__);
- for (i = 0; i < battery->dc_step_chg_step; i++)
- battery->dc_step_chg_type[i] &= ~STEP_CHARGING_CONDITION_SOC;
- }
- kfree(soc_cond_temp);
- if (dc_step_chg_type & STEP_CHARGING_CONDITION_SOC &&
- dc_step_chg_type & STEP_CHARGING_CONDITION_SOC_INIT_ONLY) {
- pr_info("%s : do not set SOC and SOC_INIT_ONLY at the same time\n", __func__);
- for (i = 0; i < battery->dc_step_chg_step; i++)
- battery->dc_step_chg_type[i] &= ~STEP_CHARGING_CONDITION_SOC;
- }
- }
- }
- if (dc_step_chg_type & STEP_CHARGING_CONDITION_FLOAT_VOLTAGE) {
- p = of_get_property(np, "battery,dc_step_chg_val_vfloat", &len);
- if (!p) {
- pr_err("%s: dc_step_chg_val_vfloat is Empty, type(0x%X->0x%x)\n",
- __func__, dc_step_chg_type,
- dc_step_chg_type & ~STEP_CHARGING_CONDITION_FLOAT_VOLTAGE);
- for (i = 0; i < battery->dc_step_chg_step; i++)
- battery->dc_step_chg_type[i] &= ~STEP_CHARGING_CONDITION_FLOAT_VOLTAGE;
- } else {
- ret = of_property_read_u32(np, "battery,dc_step_chg_cond_v_margin",
- &battery->pdata->dc_step_chg_cond_v_margin);
- if (ret)
- battery->pdata->dc_step_chg_cond_v_margin = DIRECT_CHARGING_FLOAT_VOLTAGE_MARGIN;
- pr_err("%s: dc_step_chg_cond_v_margin is %d\n",
- __func__, battery->pdata->dc_step_chg_cond_v_margin);
- len = len / sizeof(u32);
- pr_info("%s: step(%d) * age_step(%d), dc_step_chg_val_vfloat len(%d)\n",
- __func__, battery->dc_step_chg_step, num_age_step, len);
- vfloat_temp = kcalloc(battery->dc_step_chg_step * num_age_step, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,dc_step_chg_val_vfloat",
- vfloat_temp, battery->dc_step_chg_step * num_age_step);
-
- pdata->dc_step_chg_val_vfloat = kcalloc(num_age_step, sizeof(u32 *), GFP_KERNEL);
- for (i = 0; i < num_age_step; i++) {
- pdata->dc_step_chg_val_vfloat[i] =
- kcalloc(battery->dc_step_chg_step, sizeof(u32), GFP_KERNEL);
- for (j = 0; j < battery->dc_step_chg_step; j++)
- pdata->dc_step_chg_val_vfloat[i][j] =
- vfloat_temp[i*battery->dc_step_chg_step + j];
- }
-
- if (battery->dc_step_chg_step * num_age_step != len) {
- pr_err("%s: len of dc_step_chg_val_vfloat is not matched\n", __func__);
- ret = of_property_read_u32_array(np, "battery,dc_step_chg_val_vfloat",
- *pdata->dc_step_chg_val_vfloat, battery->dc_step_chg_step);
- for (i = 1; i < num_age_step; i++) {
- for (j = 0; j < battery->dc_step_chg_step; j++)
- pdata->dc_step_chg_val_vfloat[i][j] =
- pdata->dc_step_chg_val_vfloat[0][j];
- }
- }
-
- for (i = 0; i < num_age_step; i++) {
- memset(str, 0x0, sizeof(str));
- sprintf(str + strlen(str), "vfloat arr[%d]:", i);
- for (j = 0; j < battery->dc_step_chg_step; j++)
- sprintf(str + strlen(str), " %d", pdata->dc_step_chg_val_vfloat[i][j]);
- pr_info("%s: %s\n", __func__, str);
- }
- if (ret) {
- pr_info("%s : dc_step_chg_val_vfloat read fail\n", __func__);
- for (i = 0; i < battery->dc_step_chg_step; i++)
- battery->dc_step_chg_type[i] &= ~STEP_CHARGING_CONDITION_FLOAT_VOLTAGE;
- }
- kfree(vfloat_temp);
- pdata->dc_step_chg_vol_offset = kcalloc(battery->dc_step_chg_step, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,dc_step_chg_vol_offset",
- pdata->dc_step_chg_vol_offset, battery->dc_step_chg_step);
- if (ret) {
- pr_info("%s: dc_step_chg_vol_offset is empty\n", __func__);
-
- for (j = 0; j < battery->dc_step_chg_step; j++)
- if (pdata->dc_step_chg_val_vfloat[0][j] > battery->pdata->chg_float_voltage)
- pdata->dc_step_chg_vol_offset[j] =
- pdata->dc_step_chg_val_vfloat[0][j] -
- battery->pdata->chg_float_voltage;
- }
- memset(str, 0x0, sizeof(str));
- sprintf(str + strlen(str), "dc_step_chg_vol_offset arr :");
- for (i = 0; i < battery->dc_step_chg_step; i++)
- sprintf(str + strlen(str), " %d", pdata->dc_step_chg_vol_offset[i]);
- pr_info("%s: %s\n", __func__, str);
- }
- }
- p = of_get_property(np, "battery,dc_step_chg_val_iout", &len);
- if (!p) {
- pr_err("%s: dc_step_chg_val_iout is Empty\n", __func__);
- for (i = 0; i < battery->dc_step_chg_step; i++)
- battery->dc_step_chg_type[i] = 0;
- return -1;
- } else {
- len = len / sizeof(u32);
- pr_info("%s: step(%d) * age_step(%d), dc_step_chg_val_iout len(%d)\n",
- __func__, battery->dc_step_chg_step, num_age_step, len);
- iout_temp = kcalloc(battery->dc_step_chg_step * num_age_step, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,dc_step_chg_val_iout",
- iout_temp, battery->dc_step_chg_step * num_age_step);
-
- pdata->dc_step_chg_val_iout = kcalloc(num_age_step, sizeof(u32 *), GFP_KERNEL);
- for (i = 0; i < num_age_step; i++) {
- pdata->dc_step_chg_val_iout[i] =
- kcalloc(battery->dc_step_chg_step, sizeof(u32), GFP_KERNEL);
- for (j = 0; j < battery->dc_step_chg_step; j++)
- pdata->dc_step_chg_val_iout[i][j] = iout_temp[i*battery->dc_step_chg_step + j];
- }
-
- if (battery->dc_step_chg_step * num_age_step != len) {
- pr_err("%s: len of dc_step_chg_val_iout is not matched\n", __func__);
- ret = of_property_read_u32_array(np, "battery,dc_step_chg_val_iout",
- *pdata->dc_step_chg_val_iout, battery->dc_step_chg_step);
- for (i = 1; i < num_age_step; i++) {
- for (j = 0; j < battery->dc_step_chg_step; j++)
- pdata->dc_step_chg_val_iout[i][j] = pdata->dc_step_chg_val_iout[0][j];
- }
- }
-
- for (i = 0; i < num_age_step; i++) {
- memset(str, 0x0, sizeof(str));
- sprintf(str + strlen(str), "iout arr[%d]:", i);
- for (j = 0; j < battery->dc_step_chg_step; j++)
- sprintf(str + strlen(str), " %d", pdata->dc_step_chg_val_iout[i][j]);
- pr_info("%s: %s\n", __func__, str);
- }
- if (ret) {
- pr_info("%s : dc_step_chg_val_iout read fail\n", __func__);
- }
- kfree(iout_temp);
- }
- if ((dc_step_chg_type & STEP_CHARGING_CONDITION_INPUT_CURRENT) ||
- (dc_step_chg_type & STEP_CHARGING_CONDITION_FG_CURRENT)) {
- p = of_get_property(np, "battery,dc_step_chg_cond_iin", &len);
- if (!p) {
- pr_info("%s: dc_step_chg_cond_iin is Empty, set default (Iout / 2)\n", __func__);
- pdata->dc_step_chg_cond_iin =
- kcalloc(battery->dc_step_chg_step, sizeof(u32), GFP_KERNEL);
- for (i = 0; i < (battery->dc_step_chg_step - 1); i++) {
- pdata->dc_step_chg_cond_iin[i] = pdata->dc_step_chg_val_iout[age_step][i+1] / 2;
- pr_info("%s: Condition Iin [step %d] %dmA",
- __func__, i, pdata->dc_step_chg_cond_iin[i]);
- }
- pdata->dc_step_chg_cond_iin[i] = 0;
- } else {
- len = len / sizeof(u32);
- if (len != battery->dc_step_chg_step) {
- pr_err("%s: len of dc_step_chg_cond_iin is not matched, len(%d/%d)\n",
- __func__, len, battery->dc_step_chg_step);
- }
- pdata->dc_step_chg_cond_iin = kcalloc(len, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,dc_step_chg_cond_iin",
- pdata->dc_step_chg_cond_iin, len);
- if (ret) {
- pr_info("%s : dc_step_chg_cond_iin read fail\n", __func__);
- for (i = 0; i < battery->dc_step_chg_step; i++)
- battery->dc_step_chg_type[i] &= ~STEP_CHARGING_CONDITION_INPUT_CURRENT;
- }
- }
- ret = of_property_read_u32(np, "battery,dc_step_chg_iin_check_cnt",
- &battery->pdata->dc_step_chg_iin_check_cnt);
- if (ret) {
- pr_err("%s: dc_step_chg_iin_check_cnt is Empty\n", __func__);
- battery->pdata->dc_step_chg_iin_check_cnt = 2;
- } else {
- pr_err("%s: dc_step_chg_iin_check_cnt is %d\n",
- __func__, battery->pdata->dc_step_chg_iin_check_cnt);
- }
- }
-
- for (i = 0; i < battery->dc_step_chg_step; i++) {
- memset(str, 0x0, sizeof(str));
- if (battery->dc_step_chg_type[i] & STEP_CHARGING_CONDITION_VOLTAGE)
- sprintf(str + strlen(str), "cond_vol: %dmV, ", pdata->dc_step_chg_cond_vol[age_step][i]);
- if (battery->dc_step_chg_type[i] & STEP_CHARGING_CONDITION_SOC)
- sprintf(str + strlen(str), "cond_soc: %d%%, ", pdata->dc_step_chg_cond_soc[age_step][i]);
- if (battery->dc_step_chg_type[i] & STEP_CHARGING_CONDITION_INPUT_CURRENT)
- sprintf(str + strlen(str), "cond_iin: %dmA, ", pdata->dc_step_chg_cond_iin[i]);
- if (battery->dc_step_chg_type[i] & STEP_CHARGING_CONDITION_FLOAT_VOLTAGE)
- sprintf(str + strlen(str), "vfloat: %dmV, ", pdata->dc_step_chg_val_vfloat[age_step][i]);
- sprintf(str + strlen(str), "iout: %dmA,", pdata->dc_step_chg_val_iout[age_step][i]);
- pr_info("%s : step [%d] %s\n", __func__, i, str);
- }
- return 0;
- dc_step_charging_dt_error:
- return -1;
- }
- #endif
- void sec_bat_set_aging_info_step_charging(struct sec_battery_info *battery)
- {
- #if IS_ENABLED(CONFIG_DIRECT_CHARGING)
- union power_supply_propval val;
- int i = 0;
- unsigned int max_fv = 0;
- int float_volt;
- #endif
- int age_step = battery->pdata->age_step;
- #if IS_ENABLED(CONFIG_DIRECT_CHARGING)
- i = (battery->step_chg_status < 0 ? 0 : battery->step_chg_status);
- if (!battery->dc_step_chg_type[i]) {
- pr_info("%s : invalid dc step chg type\n", __func__);
- return;
- }
- #endif
- if (battery->step_chg_type) {
- if (battery->step_chg_type & STEP_CHARGING_CONDITION_FLOAT_VOLTAGE)
- battery->pdata->step_chg_vfloat[age_step][battery->step_chg_step-1] =
- battery->pdata->chg_float_voltage;
- dev_info(battery->dev, "%s: float_v(%d)\n",
- __func__, battery->pdata->step_chg_vfloat[age_step][battery->step_chg_step-1]);
- }
- #if IS_ENABLED(CONFIG_DIRECT_CHARGING)
- for (i = 0; i < battery->dc_step_chg_step; i++) {
- float_volt = battery->pdata->dc_step_chg_vol_offset[i] + battery->pdata->chg_float_voltage;
- if (battery->dc_step_chg_type[i] & STEP_CHARGING_CONDITION_FLOAT_VOLTAGE)
- if (battery->pdata->dc_step_chg_val_vfloat[age_step][i] > float_volt)
- battery->pdata->dc_step_chg_val_vfloat[age_step][i] = float_volt;
- max_fv = max(max_fv, battery->pdata->dc_step_chg_val_vfloat[age_step][i]);
- if (battery->dc_step_chg_type[i] & STEP_CHARGING_CONDITION_VOLTAGE)
- if (battery->pdata->dc_step_chg_cond_vol[age_step][i] > float_volt)
- battery->pdata->dc_step_chg_cond_vol[age_step][i] = float_volt;
- }
- for (i = 0; i < battery->dc_step_chg_step; i++) {
- dev_info(battery->dev, "%s: cond_vol: %dmV, vfloat: %dmV, cond_iin: %dmA, iout: %dmA\n", __func__,
- battery->dc_step_chg_type[i] & STEP_CHARGING_CONDITION_VOLTAGE ?
- battery->pdata->dc_step_chg_cond_vol[age_step][i] : 0,
- battery->dc_step_chg_type[i] & STEP_CHARGING_CONDITION_FLOAT_VOLTAGE ?
- battery->pdata->dc_step_chg_val_vfloat[age_step][i] : 0,
- battery->dc_step_chg_type[i] & STEP_CHARGING_CONDITION_INPUT_CURRENT ?
- battery->pdata->dc_step_chg_cond_iin[i] : 0,
- battery->pdata->dc_step_chg_val_iout[age_step][i]);
- }
- i = (battery->step_chg_status < 0 ? 0 : battery->step_chg_status);
- if (battery->dc_step_chg_type[i] & STEP_CHARGING_CONDITION_FLOAT_VOLTAGE) {
- val.intval = battery->pdata->dc_step_chg_val_vfloat[age_step][battery->dc_step_chg_step-1];
- psy_do_property(battery->pdata->charger_name, set,
- POWER_SUPPLY_EXT_PROP_DIRECT_CONSTANT_CHARGE_VOLTAGE_MAX, val);
- }
- sec_vote(battery->dc_fv_vote, VOTER_AGING_STEP, true, max_fv);
- sec_bat_reset_step_charging(battery);
- sec_bat_check_dc_step_charging(battery);
- #endif
- }
- EXPORT_SYMBOL(sec_bat_set_aging_info_step_charging);
- void sec_step_charging_dt(struct sec_battery_info *battery, struct device *dev)
- {
- struct device_node *np = dev->of_node;
- int ret, len;
- sec_battery_platform_data_t *pdata = battery->pdata;
- unsigned int i = 0, j = 0;
- const u32 *p;
- char str[128] = {0,};
- u32 *soc_cond_temp, *vfloat_temp, *curr_temp;
- int num_age_step = battery->pdata->num_age_step;
- battery->step_charging_skip_lcd_on = of_property_read_bool(np,
- "battery,step_charging_skip_lcd_on");
- battery->step_chg_en_in_factory = of_property_read_bool(np,
- "battery,step_chg_en_in_factory");
- ret = of_property_read_u32(np, "battery,step_chg_step",
- &battery->step_chg_step);
- if (ret) {
- pr_err("%s: step_chg_step is Empty\n", __func__);
- battery->step_chg_step = 0;
- } else {
- pr_err("%s: step_chg_step is %d\n",
- __func__, battery->step_chg_step);
- }
- ret = of_property_read_u32(np, "battery,step_chg_charge_power",
- &battery->step_chg_charge_power);
- if (ret) {
- pr_err("%s: step_chg_charge_power is Empty\n", __func__);
- battery->step_chg_charge_power = 20000;
- }
- p = of_get_property(np, "battery,step_chg_cond", &len);
- if (!p) {
- battery->step_chg_step = 0;
- } else {
- len = len / sizeof(u32);
- pr_info("%s: step(%d) * age_step(%d), step_chg_cond len(%d)\n",
- __func__, battery->step_chg_step, num_age_step, len);
-
- soc_cond_temp = kcalloc(battery->step_chg_step * num_age_step, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,step_chg_cond",
- soc_cond_temp, battery->step_chg_step * num_age_step);
-
- pdata->step_chg_cond = kcalloc(num_age_step, sizeof(u32 *), GFP_KERNEL);
- for (i = 0; i < num_age_step; i++) {
- pdata->step_chg_cond[i] =
- kcalloc(battery->step_chg_step, sizeof(u32), GFP_KERNEL);
- for (j = 0; j < battery->step_chg_step; j++)
- pdata->step_chg_cond[i][j] = soc_cond_temp[i*battery->step_chg_step + j];
- }
-
- if (battery->step_chg_step * num_age_step != len) {
- ret = of_property_read_u32_array(np, "battery,step_chg_cond",
- *pdata->step_chg_cond, battery->step_chg_step);
- for (i = 0; i < num_age_step; i++) {
- for (j = 0; j < battery->step_chg_step; j++)
- pdata->step_chg_cond[i][j] = pdata->step_chg_cond[0][j];
- }
- }
-
- for (i = 0; i < num_age_step; i++) {
- memset(str, 0x0, sizeof(str));
- sprintf(str + strlen(str), "step_chg_cond arr[%d]:", i);
- for (j = 0; j < battery->step_chg_step; j++)
- sprintf(str + strlen(str), " %d", pdata->step_chg_cond[i][j]);
- pr_info("%s: %s\n", __func__, str);
- }
- if (ret) {
- pr_info("%s : step_chg_cond read fail\n", __func__);
- battery->step_chg_step = 0;
- }
- kfree(soc_cond_temp);
- #if IS_ENABLED(CONFIG_DUAL_BATTERY)
- if (battery->step_chg_type & STEP_CHARGING_CONDITION_VOLTAGE) {
-
- soc_cond_temp = kcalloc(battery->step_chg_step * num_age_step, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,step_chg_cond_sub",
- soc_cond_temp, battery->step_chg_step * num_age_step);
-
- pdata->step_chg_cond_sub = kcalloc(num_age_step, sizeof(u32 *), GFP_KERNEL);
- for (i = 0; i < num_age_step; i++) {
- pdata->step_chg_cond_sub[i] =
- kcalloc(battery->step_chg_step, sizeof(u32), GFP_KERNEL);
- for (j = 0; j < battery->step_chg_step; j++)
- pdata->step_chg_cond_sub[i][j] = soc_cond_temp[i*battery->step_chg_step + j];
- }
-
- if (battery->step_chg_step * num_age_step != len) {
- ret = of_property_read_u32_array(np, "battery,step_chg_cond",
- *pdata->step_chg_cond_sub, battery->step_chg_step);
- for (i = 0; i < num_age_step; i++) {
- for (j = 0; j < battery->step_chg_step; j++)
- pdata->step_chg_cond_sub[i][j] = pdata->step_chg_cond[0][j];
- }
- }
-
- for (i = 0; i < num_age_step; i++) {
- memset(str, 0x0, sizeof(str));
- sprintf(str + strlen(str), "step_chg_cond_sub arr[%d]:", i);
- for (j = 0; j < battery->step_chg_step; j++)
- sprintf(str + strlen(str), " %d", pdata->step_chg_cond_sub[i][j]);
- pr_info("%s: %s\n", __func__, str);
- }
- if (ret)
- pr_info("%s : step_chg_cond_sub read fail\n", __func__);
- kfree(soc_cond_temp);
- }
- #endif
- p = of_get_property(np, "battery,step_chg_cond_curr", &len);
- if (!p) {
- pr_err("%s: step_chg_cond_curr is Empty\n", __func__);
- } else {
- len = len / sizeof(u32);
- pdata->step_chg_cond_curr = kcalloc(len, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,step_chg_cond_curr",
- pdata->step_chg_cond_curr, len);
- if (ret) {
- pr_info("%s : step_chg_cond_curr read fail\n", __func__);
- battery->step_chg_step = 0;
- }
- }
- p = of_get_property(np, "battery,step_chg_vfloat", &len);
- if (!p) {
- pr_err("%s: step_chg_vfloat is Empty\n", __func__);
- } else {
- len = len / sizeof(u32);
- pr_info("%s: step(%d) * age_step(%d), step_chg_vfloat len(%d)\n",
- __func__, battery->step_chg_step, num_age_step, len);
- vfloat_temp = kcalloc(battery->step_chg_step * num_age_step, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,step_chg_vfloat",
- vfloat_temp, battery->step_chg_step * num_age_step);
-
- pdata->step_chg_vfloat = kcalloc(num_age_step, sizeof(u32 *), GFP_KERNEL);
- for (i = 0; i < num_age_step; i++) {
- pdata->step_chg_vfloat[i] =
- kcalloc(battery->step_chg_step, sizeof(u32), GFP_KERNEL);
- for (j = 0; j < battery->step_chg_step; j++)
- pdata->step_chg_vfloat[i][j] =
- vfloat_temp[i*battery->step_chg_step + j];
- }
-
- if (battery->step_chg_step * num_age_step != len) {
- ret = of_property_read_u32_array(np, "battery,step_chg_vfloat",
- *pdata->step_chg_vfloat, battery->step_chg_step);
- for (i = 1; i < num_age_step; i++) {
- for (j = 0; j < battery->step_chg_step; j++)
- pdata->step_chg_vfloat[i][j] = pdata->step_chg_vfloat[0][j];
- }
- }
-
- for (i = 0; i < num_age_step; i++) {
- memset(str, 0x0, sizeof(str));
- sprintf(str + strlen(str), "step_chg_vfloat arr[%d]:", i);
- for (j = 0; j < battery->step_chg_step; j++)
- sprintf(str + strlen(str), " %d", pdata->step_chg_vfloat[i][j]);
- pr_info("%s: %s\n", __func__, str);
- }
- if (ret)
- pr_info("%s : step_chg_vfloat read fail\n", __func__);
- kfree(vfloat_temp);
- }
- p = of_get_property(np, "battery,step_chg_curr", &len);
- if (!p) {
- pr_err("%s: step_chg_curr is Empty\n", __func__);
- } else {
- len = len / sizeof(u32);
- pr_info("%s: step(%d) * age_step(%d), step_chg_curr len(%d)\n",
- __func__, battery->step_chg_step, num_age_step, len);
- curr_temp = kcalloc(battery->step_chg_step * num_age_step, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,step_chg_curr",
- curr_temp, battery->step_chg_step * num_age_step);
-
- pdata->step_chg_curr = kcalloc(num_age_step, sizeof(u32 *), GFP_KERNEL);
- for (i = 0; i < num_age_step; i++) {
- pdata->step_chg_curr[i] =
- kcalloc(battery->step_chg_step, sizeof(u32), GFP_KERNEL);
- for (j = 0; j < battery->step_chg_step; j++)
- pdata->step_chg_curr[i][j] = curr_temp[i*battery->step_chg_step + j];
- }
-
- if (battery->step_chg_step * num_age_step != len) {
- ret = of_property_read_u32_array(np, "battery,step_chg_curr",
- *pdata->step_chg_curr, battery->step_chg_step);
- for (i = 1; i < num_age_step; i++) {
- for (j = 0; j < battery->step_chg_step; j++)
- pdata->step_chg_curr[i][j] = pdata->step_chg_curr[0][j];
- }
- }
-
- for (i = 0; i < num_age_step; i++) {
- memset(str, 0x0, sizeof(str));
- sprintf(str + strlen(str), "step_chg_curr arr[%d]:", i);
- for (j = 0; j < battery->step_chg_step; j++)
- sprintf(str + strlen(str), " %d", pdata->step_chg_curr[i][j]);
- pr_info("%s: %s\n", __func__, str);
- }
- if (ret)
- pr_info("%s : step_chg_curr read fail\n", __func__);
- kfree(curr_temp);
- }
- p = of_get_property(np, "battery,step_chg_cond_soc", &len);
- if (!p) {
- pr_err("%s: step_chg_cond_soc is Empty\n", __func__);
- battery->step_chg_type =
- (battery->step_chg_type) & (~STEP_CHARGING_CONDITION_SOC_INIT_ONLY);
- } else {
- len = len / sizeof(u32);
- pr_info("%s: step(%d) * age_step(%d), step_chg_soc len(%d)\n",
- __func__, battery->step_chg_step, num_age_step, len);
- if (battery->step_chg_step * num_age_step != len) {
- pr_err("%s: mis-match len!!\n", __func__);
- battery->step_chg_type =
- (battery->step_chg_type) & (~STEP_CHARGING_CONDITION_SOC_INIT_ONLY);
- goto err_soc;
- }
- curr_temp = kcalloc(battery->step_chg_step * num_age_step, sizeof(u32), GFP_KERNEL);
- if (!curr_temp)
- goto err_soc;
- ret = of_property_read_u32_array(np, "battery,step_chg_cond_soc",
- curr_temp, battery->step_chg_step * num_age_step);
- if (ret) {
- pr_err("%s: failed to read chg_cond_soc(ret = %d)\n", __func__, ret);
- kfree(curr_temp);
- battery->step_chg_type =
- (battery->step_chg_type) & (~STEP_CHARGING_CONDITION_SOC_INIT_ONLY);
- goto err_soc;
- }
- pdata->step_chg_cond_soc = kcalloc(num_age_step, sizeof(u32 *), GFP_KERNEL);
- for (i = 0; i < num_age_step; i++) {
- pdata->step_chg_cond_soc[i] =
- kcalloc(battery->step_chg_step, sizeof(u32), GFP_KERNEL);
- for (j = 0; j < battery->step_chg_step; j++)
- pdata->step_chg_cond_soc[i][j] = curr_temp[i*battery->step_chg_step + j];
- }
- for (i = 0; i < num_age_step; i++) {
- memset(str, 0x0, sizeof(str));
- sprintf(str + strlen(str), "step_chg_cond_soc arr[%d]:", i);
- for (j = 0; j < battery->step_chg_step; j++)
- sprintf(str + strlen(str), " %d", pdata->step_chg_cond_soc[i][j]);
- pr_info("%s: %s\n", __func__, str);
- }
- err_soc:
- pr_info("%s: step_chg_soc end\n", __func__);
- }
- }
- }
- #if IS_ENABLED(CONFIG_WIRELESS_CHARGING)
- void sec_wpc_step_charging_dt(struct sec_battery_info *battery, struct device *dev)
- {
- struct device_node *np = dev->of_node;
- int ret, len;
- sec_battery_platform_data_t *pdata = battery->pdata;
- unsigned int i = 0, j = 0;
- const u32 *p;
- char str[128] = {0,};
- u32 *soc_cond_temp, *vfloat_temp, *curr_temp;
- int num_age_step = battery->pdata->num_age_step;
- ret = of_property_read_u32(np, "battery,wpc_step_chg_step",
- &battery->wpc_step_chg_step);
- if (ret) {
- pr_err("%s: wpc_step_chg_step is Empty\n", __func__);
- battery->wpc_step_chg_step = 0;
- } else {
- pr_err("%s: wpc_step_chg_step is %d\n",
- __func__, battery->wpc_step_chg_step);
- }
- ret = of_property_read_u32(np, "battery,wpc_step_chg_charge_power",
- &battery->wpc_step_chg_charge_power);
- if (ret) {
- pr_err("%s: wpc_step_chg_charge_power is Empty\n", __func__);
- battery->wpc_step_chg_charge_power = 7500;
- }
- p = of_get_property(np, "battery,wpc_step_chg_cond", &len);
- if (!p) {
- battery->wpc_step_chg_step = 0;
- } else {
- len = len / sizeof(u32);
- pr_info("%s: step(%d) * age_step(%d), step_chg_cond len(%d)\n",
- __func__, battery->wpc_step_chg_step, num_age_step, len);
-
- soc_cond_temp = kcalloc(battery->wpc_step_chg_step * num_age_step, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,wpc_step_chg_cond",
- soc_cond_temp, battery->wpc_step_chg_step * num_age_step);
-
- pdata->wpc_step_chg_cond = kcalloc(num_age_step, sizeof(u32 *), GFP_KERNEL);
- for (i = 0; i < num_age_step; i++) {
- pdata->wpc_step_chg_cond[i] =
- kcalloc(battery->wpc_step_chg_step, sizeof(u32), GFP_KERNEL);
- for (j = 0; j < battery->wpc_step_chg_step; j++)
- pdata->wpc_step_chg_cond[i][j] = soc_cond_temp[i*battery->wpc_step_chg_step + j];
- }
-
- if (battery->wpc_step_chg_step * num_age_step != len) {
- ret = of_property_read_u32_array(np, "battery,wpc_step_chg_cond",
- *pdata->wpc_step_chg_cond, battery->wpc_step_chg_step);
- for (i = 0; i < num_age_step; i++) {
- for (j = 0; j < battery->wpc_step_chg_step; j++)
- pdata->wpc_step_chg_cond[i][j] = pdata->wpc_step_chg_cond[0][j];
- }
- }
-
- for (i = 0; i < num_age_step; i++) {
- memset(str, 0x0, sizeof(str));
- sprintf(str + strlen(str), "wpc_step_chg_cond arr[%d]:", i);
- for (j = 0; j < battery->wpc_step_chg_step; j++)
- sprintf(str + strlen(str), " %d", pdata->wpc_step_chg_cond[i][j]);
- pr_info("%s: %s\n", __func__, str);
- }
- if (ret) {
- pr_info("%s : wpc_step_chg_cond read fail\n", __func__);
- battery->wpc_step_chg_step = 0;
- }
- kfree(soc_cond_temp);
- p = of_get_property(np, "battery,wpc_step_chg_cond_curr", &len);
- if (!p) {
- pr_err("%s: wpc_step_chg_cond_curr is Empty\n", __func__);
- } else {
- len = len / sizeof(u32);
- pdata->wpc_step_chg_cond_curr = kcalloc(len, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,wpc_step_chg_cond_curr",
- pdata->wpc_step_chg_cond_curr, len);
- if (ret) {
- pr_info("%s : wpc_step_chg_cond_curr read fail\n", __func__);
- battery->wpc_step_chg_step = 0;
- }
- }
- p = of_get_property(np, "battery,wpc_step_chg_vfloat", &len);
- if (!p) {
- pr_err("%s: wpc_step_chg_vfloat is Empty\n", __func__);
- } else {
- len = len / sizeof(u32);
- pr_info("%s: step(%d) * age_step(%d), wpc_step_chg_vfloat len(%d)\n",
- __func__, battery->wpc_step_chg_step, num_age_step, len);
- vfloat_temp = kcalloc(battery->wpc_step_chg_step * num_age_step, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,wpc_step_chg_vfloat",
- vfloat_temp, battery->wpc_step_chg_step * num_age_step);
-
- pdata->wpc_step_chg_vfloat = kcalloc(num_age_step, sizeof(u32 *), GFP_KERNEL);
- for (i = 0; i < num_age_step; i++) {
- pdata->wpc_step_chg_vfloat[i] =
- kcalloc(battery->wpc_step_chg_step, sizeof(u32), GFP_KERNEL);
- for (j = 0; j < battery->wpc_step_chg_step; j++)
- pdata->wpc_step_chg_vfloat[i][j] =
- vfloat_temp[i*battery->wpc_step_chg_step + j];
- }
-
- if (battery->wpc_step_chg_step * num_age_step != len) {
- ret = of_property_read_u32_array(np, "battery,wpc_step_chg_vfloat",
- *pdata->wpc_step_chg_vfloat, battery->wpc_step_chg_step);
- for (i = 1; i < num_age_step; i++) {
- for (j = 0; j < battery->wpc_step_chg_step; j++)
- pdata->wpc_step_chg_vfloat[i][j] = pdata->wpc_step_chg_vfloat[0][j];
- }
- }
-
- for (i = 0; i < num_age_step; i++) {
- memset(str, 0x0, sizeof(str));
- sprintf(str + strlen(str), "wpc_step_chg_vfloat arr[%d]:", i);
- for (j = 0; j < battery->wpc_step_chg_step; j++)
- sprintf(str + strlen(str), " %d", pdata->wpc_step_chg_vfloat[i][j]);
- pr_info("%s: %s\n", __func__, str);
- }
- if (ret)
- pr_info("%s : wpc_step_chg_vfloat read fail\n", __func__);
- kfree(vfloat_temp);
- }
- p = of_get_property(np, "battery,wpc_step_chg_curr", &len);
- if (!p) {
- pr_err("%s: wpc_step_chg_curr is Empty\n", __func__);
- } else {
- len = len / sizeof(u32);
- pr_info("%s: step(%d) * age_step(%d), wpc_step_chg_curr len(%d)\n",
- __func__, battery->wpc_step_chg_step, num_age_step, len);
- curr_temp = kcalloc(battery->wpc_step_chg_step * num_age_step, sizeof(u32), GFP_KERNEL);
- ret = of_property_read_u32_array(np, "battery,wpc_step_chg_curr",
- curr_temp, battery->wpc_step_chg_step * num_age_step);
-
- pdata->wpc_step_chg_curr = kcalloc(num_age_step, sizeof(u32 *), GFP_KERNEL);
- for (i = 0; i < num_age_step; i++) {
- pdata->wpc_step_chg_curr[i] =
- kcalloc(battery->wpc_step_chg_step, sizeof(u32), GFP_KERNEL);
- for (j = 0; j < battery->wpc_step_chg_step; j++)
- pdata->wpc_step_chg_curr[i][j] = curr_temp[i*battery->wpc_step_chg_step + j];
- }
-
- if (battery->wpc_step_chg_step * num_age_step != len) {
- ret = of_property_read_u32_array(np, "battery,wpc_step_chg_curr",
- *pdata->wpc_step_chg_curr, battery->wpc_step_chg_step);
- for (i = 1; i < num_age_step; i++) {
- for (j = 0; j < battery->wpc_step_chg_step; j++)
- pdata->wpc_step_chg_curr[i][j] = pdata->wpc_step_chg_curr[0][j];
- }
- }
-
- for (i = 0; i < num_age_step; i++) {
- memset(str, 0x0, sizeof(str));
- sprintf(str + strlen(str), "wpc_step_chg_curr arr[%d]:", i);
- for (j = 0; j < battery->wpc_step_chg_step; j++)
- sprintf(str + strlen(str), " %d", pdata->wpc_step_chg_curr[i][j]);
- pr_info("%s: %s\n", __func__, str);
- }
- if (ret)
- pr_info("%s : wpc_step_chg_curr read fail\n", __func__);
- kfree(curr_temp);
- }
- }
- }
- #endif
- void sec_step_charging_init(struct sec_battery_info *battery, struct device *dev)
- {
- struct device_node *np = dev->of_node;
- int ret;
- battery->step_chg_status = -1;
- ret = of_property_read_u32(np, "battery,step_chg_type",
- &battery->step_chg_type);
- pr_err("%s: step_chg_type 0x%x\n", __func__, battery->step_chg_type);
- if (ret) {
- pr_err("%s: step_chg_type is Empty\n", __func__);
- battery->step_chg_type = 0;
- }
- if (battery->step_chg_type)
- sec_step_charging_dt(battery, dev);
- #if IS_ENABLED(CONFIG_WIRELESS_CHARGING)
- ret = of_property_read_u32(np, "battery,wpc_step_chg_type",
- &battery->wpc_step_chg_type);
- pr_err("%s: wpc_step_chg_type 0x%x\n", __func__, battery->wpc_step_chg_type);
- if (ret) {
- pr_err("%s: wpc_step_chg_type is Empty\n", __func__);
- battery->wpc_step_chg_type = 0;
- }
- if (battery->wpc_step_chg_type)
- sec_wpc_step_charging_dt(battery, dev);
- #endif
- #if IS_ENABLED(CONFIG_DIRECT_CHARGING)
- sec_dc_step_charging_dt(battery, dev);
- #endif
- }
- EXPORT_SYMBOL(sec_step_charging_init);
|