| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516 |
- #include <linux/init.h> /* For init/exit macros */
- #include <linux/module.h> /* For MODULE_ marcros */
- #include <linux/fs.h>
- #include <linux/device.h>
- #include <linux/interrupt.h>
- #include <linux/spinlock.h>
- #include <linux/platform_device.h>
- #include <linux/device.h>
- #include <linux/kdev_t.h>
- #include <linux/fs.h>
- #include <linux/cdev.h>
- #include <linux/delay.h>
- #include <linux/kernel.h>
- #include <linux/init.h>
- #include <linux/types.h>
- #include <linux/wait.h>
- #include <linux/slab.h>
- #include <linux/fs.h>
- #include <linux/sched.h>
- #include <linux/poll.h>
- #include <linux/power_supply.h>
- #include <linux/wakelock.h>
- #include <linux/time.h>
- #include <linux/mutex.h>
- #include <linux/kthread.h>
- #include <linux/proc_fs.h>
- #include <linux/platform_device.h>
- #include <linux/seq_file.h>
- #include <linux/of.h>
- #include <asm/uaccess.h>
- #include <asm/io.h>
- #include <asm/irq.h>
- #include <mt-plat/mt_boot.h>
- #include "mt_charging.h"
- #include "mt_battery_custom_data.h"
- #include "mt_battery_common.h"
- #include "mt_battery_meter.h"
- #include <linux/irq.h>
- #include <linux/reboot.h>
- struct battery_common_data g_bat;
- /* Battery Notify */
- #define BATTERY_NOTIFY_CASE_0001_VCHARGER
- #define BATTERY_NOTIFY_CASE_0002_VBATTEMP
- /* #define BATTERY_NOTIFY_CASE_0003_ICHARGING */
- #define BATTERY_NOTIFY_CASE_0004_VBAT
- #define BATTERY_NOTIFY_CASE_0005_TOTAL_CHARGINGTIME
- /* Precise Tunning */
- #define BATTERY_AVERAGE_DATA_NUMBER 3
- #define BATTERY_AVERAGE_SIZE 30
- #define CUST_CAPACITY_OCV2CV_TRANSFORM
- /* ////////////////////////////////////////////////////////////////////////////// */
- /* Battery Logging Entry */
- /* ////////////////////////////////////////////////////////////////////////////// */
- int Enable_BATDRV_LOG = BAT_LOG_ERROR;
- char proc_bat_data[32];
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Smart Battery Structure */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- struct PMU_ChargerStruct BMT_status;
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Thermal related flags */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* 0:nothing, 1:enable batTT&chrTimer, 2:disable batTT&chrTimer, 3:enable batTT, disable chrTimer */
- int g_battery_thermal_throttling_flag = 3;
- int battery_cmd_thermal_test_mode = 0;
- int battery_cmd_thermal_test_mode_value = 0;
- int g_battery_tt_check_flag = 0; /* 0:default enable check batteryTT, 1:default disable check batteryTT */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Global Variable */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- #ifdef CONFIG_OF
- static const struct of_device_id mt_battery_common_id[] = {
- {.compatible = "mediatek,battery_common"},
- {},
- };
- MODULE_DEVICE_TABLE(of, mt_battery_common_id);
- #endif
- struct wake_lock battery_suspend_lock;
- unsigned int g_BatteryNotifyCode = 0x0000;
- unsigned int g_BN_TestMode = 0x0000;
- bool g_bat_init_flag = 0;
- bool g_call_state = CALL_IDLE;
- bool g_charging_full_reset_bat_meter = false;
- int g_platform_boot_mode = 0;
- static bool battery_meter_initilized;
- bool g_cmd_hold_charging = false;
- s32 g_custom_charging_current = -1;
- bool battery_suspended = false;
- bool g_refresh_ui_soc = false;
- static bool fg_battery_shutdown;
- struct mt_battery_charging_custom_data *p_bat_charging_data;
- static struct mt_battery_charging_custom_data default_charging_data = {
- .talking_recharge_voltage = 3800,
- .talking_sync_time = 60,
- /* Battery Temperature Protection */
- .max_discharge_temperature = 60,
- .min_discharge_temperature = -10,
- .max_charge_temperature = 50,
- .min_charge_temperature = 0,
- .err_charge_temperature = 0xFF,
- .use_avg_temperature = 1,
- /* Linear Charging Threshold */
- .v_pre2cc_thres = 3400, /* mV */
- .v_cc2topoff_thres = 4050,
- .recharging_voltage = 4110,
- .charging_full_current = 150, /* mA */
- /* CONFIG_USB_IF */
- .usb_charger_current_suspend = 0,
- .usb_charger_current_unconfigured = CHARGE_CURRENT_70_00_MA,
- .usb_charger_current_configured = CHARGE_CURRENT_500_00_MA,
- .usb_charger_current = CHARGE_CURRENT_500_00_MA,
- .ac_charger_current = 204800,
- .non_std_ac_charger_current = CHARGE_CURRENT_500_00_MA,
- .charging_host_charger_current = CHARGE_CURRENT_650_00_MA,
- .apple_0_5a_charger_current = CHARGE_CURRENT_500_00_MA,
- .apple_1_0a_charger_current = CHARGE_CURRENT_1000_00_MA,
- .apple_2_1a_charger_current = CHARGE_CURRENT_2000_00_MA,
- /* Charger error check */
- /* BAT_LOW_TEMP_PROTECT_ENABLE */
- .v_charger_enable = 0, /* 1:ON , 0:OFF */
- .v_charger_max = 6500, /* 6.5 V */
- .v_charger_min = 4400, /* 4.4 V */
- /* Tracking time */
- .onehundred_percent_tracking_time = 10, /* 10 second */
- .npercent_tracking_time = 20, /* 20 second */
- .sync_to_real_tracking_time = 30, /* 30 second */
- /* JEITA parameter */
- .cust_soc_jeita_sync_time = 30,
- .jeita_recharge_voltage = 4110, /* for linear charging */
- .jeita_temp_above_pos_60_cv_voltage = BATTERY_VOLT_04_000000_V,
- .jeita_temp_pos_45_to_pos_60_cv_voltage = BATTERY_VOLT_04_000000_V,
- .jeita_temp_pos_10_to_pos_45_cv_voltage = BATTERY_VOLT_04_200000_V,
- .jeita_temp_pos_0_to_pos_10_cv_voltage = BATTERY_VOLT_04_000000_V,
- .jeita_temp_neg_10_to_pos_0_cv_voltage = BATTERY_VOLT_04_000000_V,
- .jeita_temp_below_neg_10_cv_voltage = BATTERY_VOLT_04_000000_V,
- .temp_pos_60_threshold = 50,
- .temp_pos_60_thres_minus_x_degree = 47,
- .temp_pos_45_threshold = 45,
- .temp_pos_45_thres_minus_x_degree = 39,
- .temp_pos_10_threshold = 10,
- .temp_pos_10_thres_plus_x_degree = 16,
- .temp_pos_0_threshold = 0,
- .temp_pos_0_thres_plus_x_degree = 6,
- .temp_neg_10_threshold = 0,
- .temp_neg_10_thres_plus_x_degree = 0,
- /* For JEITA Linear Charging Only */
- .jeita_neg_10_to_pos_0_full_current = 120, /* mA */
- .jeita_temp_pos_45_to_pos_60_recharge_voltage = 4000,
- .jeita_temp_pos_10_to_pos_45_recharge_voltage = 4100,
- .jeita_temp_pos_0_to_pos_10_recharge_voltage = 4000,
- .jeita_temp_neg_10_to_pos_0_recharge_voltage = 3800,
- .jeita_temp_pos_45_to_pos_60_cc2topoff_threshold = 4050,
- .jeita_temp_pos_10_to_pos_45_cc2topoff_threshold = 4050,
- .jeita_temp_pos_0_to_pos_10_cc2topoff_threshold = 4050,
- .jeita_temp_neg_10_to_pos_0_cc2topoff_threshold = 3850,
- /* For Pump Express Plus */
- .ta_start_battery_soc = 1,
- .ta_stop_battery_soc = 95,
- .ta_ac_9v_input_current = CHARGE_CURRENT_1500_00_MA,
- .ta_ac_7v_input_current = CHARGE_CURRENT_1500_00_MA,
- .ta_ac_charging_current = CHARGE_CURRENT_2200_00_MA,
- .ta_9v_support = 1,
- };
- /* ////////////////////////////////////////////////////////////////////////////// */
- /* Integrate with NVRAM */
- /* ////////////////////////////////////////////////////////////////////////////// */
- #define ADC_CALI_DEVNAME "MT_pmic_adc_cali"
- #define TEST_ADC_CALI_PRINT _IO('k', 0)
- #define SET_ADC_CALI_Slop _IOW('k', 1, int)
- #define SET_ADC_CALI_Offset _IOW('k', 2, int)
- #define SET_ADC_CALI_Cal _IOW('k', 3, int)
- #define ADC_CHANNEL_READ _IOW('k', 4, int)
- #define BAT_STATUS_READ _IOW('k', 5, int)
- #define Set_Charger_Current _IOW('k', 6, int)
- /* add for meta tool----------------------------------------- */
- #define Get_META_BAT_VOL _IOW('k', 10, int)
- #define Get_META_BAT_SOC _IOW('k', 11, int)
- /* add for meta tool----------------------------------------- */
- static struct class *adc_cali_class;
- static int adc_cali_major;
- static dev_t adc_cali_devno;
- static struct cdev *adc_cali_cdev;
- int adc_cali_slop[14] = {
- 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000
- };
- int adc_cali_offset[14] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- int adc_cali_cal[1] = { 0 };
- int battery_in_data[1] = { 0 };
- int battery_out_data[1] = { 0 };
- int charging_level_data[1] = { 0 };
- bool g_ADC_Cali = false;
- bool g_ftm_battery_flag = false;
- static bool need_clear_current_window;
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Thread related */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- #define BAT_MS_TO_NS(x) (x * 1000 * 1000)
- static atomic_t bat_thread_wakeup;
- static bool chr_wake_up_bat; /* charger in/out to wake up battery thread */
- static bool bat_meter_timeout;
- static DEFINE_MUTEX(bat_mutex);
- static DEFINE_MUTEX(charger_type_mutex);
- static DECLARE_WAIT_QUEUE_HEAD(bat_thread_wq);
- /* ////////////////////////////////////////////////////////////////////////////// */
- /* FOR ANDROID BATTERY SERVICE */
- /* ////////////////////////////////////////////////////////////////////////////// */
- struct ac_data {
- struct power_supply psy;
- int AC_ONLINE;
- };
- struct usb_data {
- struct power_supply psy;
- int USB_ONLINE;
- };
- struct battery_data {
- struct power_supply psy;
- int BAT_STATUS;
- int BAT_HEALTH;
- int BAT_PRESENT;
- int BAT_TECHNOLOGY;
- int BAT_CAPACITY;
- /* Add for Battery Service */
- int BAT_VOLTAGE_NOW;
- int BAT_VOLTAGE_AVG;
- int BAT_TEMP;
- /* Add for EM */
- int BAT_TemperatureR;
- int BAT_TempBattVoltage;
- int BAT_InstatVolt;
- int BAT_BatteryAverageCurrent;
- int BAT_BatterySenseVoltage;
- int BAT_ISenseVoltage;
- int BAT_ChargerVoltage;
- };
- static enum power_supply_property ac_props[] = {
- POWER_SUPPLY_PROP_ONLINE,
- };
- static enum power_supply_property usb_props[] = {
- POWER_SUPPLY_PROP_ONLINE,
- };
- static enum power_supply_property battery_props[] = {
- POWER_SUPPLY_PROP_STATUS,
- POWER_SUPPLY_PROP_HEALTH,
- POWER_SUPPLY_PROP_PRESENT,
- POWER_SUPPLY_PROP_TECHNOLOGY,
- POWER_SUPPLY_PROP_CAPACITY,
- /* Add for Battery Service */
- POWER_SUPPLY_PROP_VOLTAGE_NOW,
- POWER_SUPPLY_PROP_VOLTAGE_AVG,
- POWER_SUPPLY_PROP_TEMP,
- /* Add for EM
- POWER_SUPPLY_PROP_TemperatureR,
- POWER_SUPPLY_PROP_TempBattVoltage,
- POWER_SUPPLY_PROP_InstatVolt,
- POWER_SUPPLY_PROP_BatteryAverageCurrent,
- POWER_SUPPLY_PROP_BatterySenseVoltage,
- POWER_SUPPLY_PROP_ISenseVoltage,
- POWER_SUPPLY_PROP_ChargerVoltage,
- */
- };
- int read_tbat_value(void)
- {
- return BMT_status.temperature;
- }
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // PMIC PCHR Related APIs */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- bool upmu_is_chr_det(void)
- {
- #if defined(CONFIG_POWER_EXT)
- /* return true; */
- return bat_charger_get_detect_status();
- #else
- u32 tmp32;
- tmp32 = bat_charger_get_detect_status();
- if (tmp32 == 0)
- return false;
- if (mt_usb_is_device()) {
- battery_log(BAT_LOG_FULL, "[upmu_is_chr_det] Charger exist and USB is not host\n");
- return true;
- }
- battery_log(BAT_LOG_FULL, "[upmu_is_chr_det] Charger exist but USB is host\n");
- return false;
- #endif
- }
- EXPORT_SYMBOL(upmu_is_chr_det);
- static inline void _do_wake_up_bat_thread(void)
- {
- atomic_inc(&bat_thread_wakeup);
- wake_up(&bat_thread_wq);
- }
- /* for charger plug-in/out */
- void wake_up_bat(void)
- {
- pr_debug("%s:\n", __func__);
- chr_wake_up_bat = true;
- _do_wake_up_bat_thread();
- }
- EXPORT_SYMBOL(wake_up_bat);
- /* for meter update */
- static void wake_up_bat_update_meter(void)
- {
- pr_debug("%s:\n", __func__);
- bat_meter_timeout = true;
- _do_wake_up_bat_thread();
- }
- static ssize_t bat_log_write(struct file *filp, const char __user *buff, size_t len, loff_t *data)
- {
- if (copy_from_user(&proc_bat_data, buff, len)) {
- battery_log(BAT_LOG_FULL, "bat_log_write error.\n");
- return -EFAULT;
- }
- if (proc_bat_data[0] == '1') {
- battery_log(BAT_LOG_CRTI, "enable battery driver log system\n");
- Enable_BATDRV_LOG = 1;
- } else if (proc_bat_data[0] == '2') {
- battery_log(BAT_LOG_CRTI, "enable battery driver log system:2\n");
- Enable_BATDRV_LOG = 2;
- } else {
- battery_log(BAT_LOG_CRTI, "Disable battery driver log system\n");
- Enable_BATDRV_LOG = 0;
- }
- return len;
- }
- static const struct file_operations bat_proc_fops = {
- .write = bat_log_write,
- };
- int init_proc_log(void)
- {
- int ret = 0;
- proc_create("batdrv_log", 0644, NULL, &bat_proc_fops);
- battery_log(BAT_LOG_CRTI, "proc_create bat_proc_fops\n");
- return ret;
- }
- static int ac_get_property(struct power_supply *psy,
- enum power_supply_property psp, union power_supply_propval *val)
- {
- int ret = 0;
- struct ac_data *data = container_of(psy, struct ac_data, psy);
- switch (psp) {
- case POWER_SUPPLY_PROP_ONLINE:
- val->intval = data->AC_ONLINE;
- break;
- default:
- ret = -EINVAL;
- break;
- }
- return ret;
- }
- static int usb_get_property(struct power_supply *psy,
- enum power_supply_property psp, union power_supply_propval *val)
- {
- int ret = 0;
- struct usb_data *data = container_of(psy, struct usb_data, psy);
- switch (psp) {
- case POWER_SUPPLY_PROP_ONLINE:
- #if defined(CONFIG_POWER_EXT)
- /* #if 0 */
- data->USB_ONLINE = 1;
- val->intval = data->USB_ONLINE;
- #else
- val->intval = data->USB_ONLINE;
- #endif
- break;
- default:
- ret = -EINVAL;
- break;
- }
- return ret;
- }
- static int battery_get_property(struct power_supply *psy,
- enum power_supply_property psp, union power_supply_propval *val)
- {
- int ret = 0;
- struct battery_data *data = container_of(psy, struct battery_data, psy);
- switch (psp) {
- case POWER_SUPPLY_PROP_STATUS:
- val->intval = data->BAT_STATUS;
- break;
- case POWER_SUPPLY_PROP_HEALTH:
- val->intval = data->BAT_HEALTH;
- break;
- case POWER_SUPPLY_PROP_PRESENT:
- val->intval = data->BAT_PRESENT;
- break;
- case POWER_SUPPLY_PROP_TECHNOLOGY:
- val->intval = data->BAT_TECHNOLOGY;
- break;
- case POWER_SUPPLY_PROP_CAPACITY:
- val->intval = data->BAT_CAPACITY;
- break;
- case POWER_SUPPLY_PROP_VOLTAGE_NOW:
- val->intval = data->BAT_VOLTAGE_NOW;
- break;
- case POWER_SUPPLY_PROP_TEMP:
- val->intval = data->BAT_TEMP;
- break;
- case POWER_SUPPLY_PROP_VOLTAGE_AVG:
- val->intval = data->BAT_VOLTAGE_AVG;
- break;
- /*
- case POWER_SUPPLY_PROP_TemperatureR:
- val->intval = data->BAT_TemperatureR;
- break;
- case POWER_SUPPLY_PROP_TempBattVoltage:
- val->intval = data->BAT_TempBattVoltage;
- break;
- case POWER_SUPPLY_PROP_InstatVolt:
- val->intval = data->BAT_InstatVolt;
- break;
- case POWER_SUPPLY_PROP_BatteryAverageCurrent:
- val->intval = data->BAT_BatteryAverageCurrent;
- break;
- case POWER_SUPPLY_PROP_BatterySenseVoltage:
- val->intval = data->BAT_BatterySenseVoltage;
- break;
- case POWER_SUPPLY_PROP_ISenseVoltage:
- val->intval = data->BAT_ISenseVoltage;
- break;
- case POWER_SUPPLY_PROP_ChargerVoltage:
- val->intval = data->BAT_ChargerVoltage;
- break;
- */
- default:
- ret = -EINVAL;
- break;
- }
- return ret;
- }
- /* ac_data initialization */
- static struct ac_data ac_main = {
- .psy = {
- .name = "ac",
- .type = POWER_SUPPLY_TYPE_MAINS,
- .properties = ac_props,
- .num_properties = ARRAY_SIZE(ac_props),
- .get_property = ac_get_property,
- },
- .AC_ONLINE = 0,
- };
- /* usb_data initialization */
- static struct usb_data usb_main = {
- .psy = {
- .name = "usb",
- .type = POWER_SUPPLY_TYPE_USB,
- .properties = usb_props,
- .num_properties = ARRAY_SIZE(usb_props),
- .get_property = usb_get_property,
- },
- .USB_ONLINE = 0,
- };
- /* battery_data initialization */
- static struct battery_data battery_main = {
- .psy = {
- .name = "battery",
- .type = POWER_SUPPLY_TYPE_BATTERY,
- .properties = battery_props,
- .num_properties = ARRAY_SIZE(battery_props),
- .get_property = battery_get_property,
- },
- /* CC: modify to have a full power supply status */
- #if defined(CONFIG_POWER_EXT)
- .BAT_STATUS = POWER_SUPPLY_STATUS_FULL,
- .BAT_HEALTH = POWER_SUPPLY_HEALTH_GOOD,
- .BAT_PRESENT = 1,
- .BAT_TECHNOLOGY = POWER_SUPPLY_TECHNOLOGY_LION,
- .BAT_CAPACITY = 100,
- .BAT_VOLTAGE_NOW = 4200000,
- .BAT_VOLTAGE_AVG = 4200000,
- .BAT_TEMP = 22,
- #else
- .BAT_STATUS = POWER_SUPPLY_STATUS_NOT_CHARGING,
- .BAT_HEALTH = POWER_SUPPLY_HEALTH_GOOD,
- .BAT_PRESENT = 1,
- .BAT_TECHNOLOGY = POWER_SUPPLY_TECHNOLOGY_LION,
- #if defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT)
- .BAT_CAPACITY = -1,
- #else
- .BAT_CAPACITY = 50,
- #endif
- .BAT_VOLTAGE_NOW = 0,
- .BAT_VOLTAGE_AVG = 0,
- .BAT_TEMP = 0,
- #endif
- };
- #if !defined(CONFIG_POWER_EXT)
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Charger_Voltage */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Charger_Voltage(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- battery_log(BAT_LOG_CRTI, "[EM] show_ADC_Charger_Voltage : %d\n", BMT_status.charger_vol);
- return sprintf(buf, "%d\n", BMT_status.charger_vol);
- }
- static ssize_t store_ADC_Charger_Voltage(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Charger_Voltage, 0664, show_ADC_Charger_Voltage, store_ADC_Charger_Voltage);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_0_Slope */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_0_Slope(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_slop + 0));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_0_Slope : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_0_Slope(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_0_Slope, 0664, show_ADC_Channel_0_Slope, store_ADC_Channel_0_Slope);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_1_Slope */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_1_Slope(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_slop + 1));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_1_Slope : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_1_Slope(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_1_Slope, 0664, show_ADC_Channel_1_Slope, store_ADC_Channel_1_Slope);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_2_Slope */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_2_Slope(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_slop + 2));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_2_Slope : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_2_Slope(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_2_Slope, 0664, show_ADC_Channel_2_Slope, store_ADC_Channel_2_Slope);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_3_Slope */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_3_Slope(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_slop + 3));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_3_Slope : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_3_Slope(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_3_Slope, 0664, show_ADC_Channel_3_Slope, store_ADC_Channel_3_Slope);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_4_Slope */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_4_Slope(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_slop + 4));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_4_Slope : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_4_Slope(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_4_Slope, 0664, show_ADC_Channel_4_Slope, store_ADC_Channel_4_Slope);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_5_Slope */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_5_Slope(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_slop + 5));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_5_Slope : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_5_Slope(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_5_Slope, 0664, show_ADC_Channel_5_Slope, store_ADC_Channel_5_Slope);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_6_Slope */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_6_Slope(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_slop + 6));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_6_Slope : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_6_Slope(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_6_Slope, 0664, show_ADC_Channel_6_Slope, store_ADC_Channel_6_Slope);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_7_Slope */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_7_Slope(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_slop + 7));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_7_Slope : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_7_Slope(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_7_Slope, 0664, show_ADC_Channel_7_Slope, store_ADC_Channel_7_Slope);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_8_Slope */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_8_Slope(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_slop + 8));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_8_Slope : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_8_Slope(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_8_Slope, 0664, show_ADC_Channel_8_Slope, store_ADC_Channel_8_Slope);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_9_Slope */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_9_Slope(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_slop + 9));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_9_Slope : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_9_Slope(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_9_Slope, 0664, show_ADC_Channel_9_Slope, store_ADC_Channel_9_Slope);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_10_Slope */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_10_Slope(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_slop + 10));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_10_Slope : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_10_Slope(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_10_Slope, 0664, show_ADC_Channel_10_Slope,
- store_ADC_Channel_10_Slope);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_11_Slope */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_11_Slope(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_slop + 11));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_11_Slope : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_11_Slope(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_11_Slope, 0664, show_ADC_Channel_11_Slope,
- store_ADC_Channel_11_Slope);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_12_Slope */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_12_Slope(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_slop + 12));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_12_Slope : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_12_Slope(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_12_Slope, 0664, show_ADC_Channel_12_Slope,
- store_ADC_Channel_12_Slope);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_13_Slope */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_13_Slope(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_slop + 13));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_13_Slope : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_13_Slope(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_13_Slope, 0664, show_ADC_Channel_13_Slope,
- store_ADC_Channel_13_Slope);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_0_Offset */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_0_Offset(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_offset + 0));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_0_Offset : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_0_Offset(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_0_Offset, 0664, show_ADC_Channel_0_Offset,
- store_ADC_Channel_0_Offset);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_1_Offset */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_1_Offset(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_offset + 1));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_1_Offset : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_1_Offset(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_1_Offset, 0664, show_ADC_Channel_1_Offset,
- store_ADC_Channel_1_Offset);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_2_Offset */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_2_Offset(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_offset + 2));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_2_Offset : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_2_Offset(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_2_Offset, 0664, show_ADC_Channel_2_Offset,
- store_ADC_Channel_2_Offset);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_3_Offset */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_3_Offset(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_offset + 3));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_3_Offset : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_3_Offset(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_3_Offset, 0664, show_ADC_Channel_3_Offset,
- store_ADC_Channel_3_Offset);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_4_Offset */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_4_Offset(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_offset + 4));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_4_Offset : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_4_Offset(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_4_Offset, 0664, show_ADC_Channel_4_Offset,
- store_ADC_Channel_4_Offset);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_5_Offset */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_5_Offset(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_offset + 5));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_5_Offset : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_5_Offset(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_5_Offset, 0664, show_ADC_Channel_5_Offset,
- store_ADC_Channel_5_Offset);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_6_Offset */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_6_Offset(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_offset + 6));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_6_Offset : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_6_Offset(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_6_Offset, 0664, show_ADC_Channel_6_Offset,
- store_ADC_Channel_6_Offset);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_7_Offset */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_7_Offset(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_offset + 7));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_7_Offset : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_7_Offset(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_7_Offset, 0664, show_ADC_Channel_7_Offset,
- store_ADC_Channel_7_Offset);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_8_Offset */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_8_Offset(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_offset + 8));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_8_Offset : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_8_Offset(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_8_Offset, 0664, show_ADC_Channel_8_Offset,
- store_ADC_Channel_8_Offset);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_9_Offset */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_9_Offset(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_offset + 9));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_9_Offset : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_9_Offset(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_9_Offset, 0664, show_ADC_Channel_9_Offset,
- store_ADC_Channel_9_Offset);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_10_Offset */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_10_Offset(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_offset + 10));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_10_Offset : %d\n", ret_value);
- return sprintf(buf, "%d\n", ret_value);
- }
- static ssize_t store_ADC_Channel_10_Offset(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_10_Offset, 0664, show_ADC_Channel_10_Offset,
- store_ADC_Channel_10_Offset);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_11_Offset */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_11_Offset(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_offset + 11));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_11_Offset : %d\n", ret_value);
- return sprintf(buf, "%d\n", ret_value);
- }
- static ssize_t store_ADC_Channel_11_Offset(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_11_Offset, 0664, show_ADC_Channel_11_Offset,
- store_ADC_Channel_11_Offset);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_12_Offset */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_12_Offset(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_offset + 12));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_12_Offset : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_12_Offset(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_12_Offset, 0664, show_ADC_Channel_12_Offset,
- store_ADC_Channel_12_Offset);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_13_Offset */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_13_Offset(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = (*(adc_cali_offset + 13));
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_13_Offset : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_13_Offset(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_13_Offset, 0664, show_ADC_Channel_13_Offset,
- store_ADC_Channel_13_Offset);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : ADC_Channel_Is_Calibration */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_ADC_Channel_Is_Calibration(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 2;
- ret_value = g_ADC_Cali;
- battery_log(BAT_LOG_CRTI, "[EM] ADC_Channel_Is_Calibration : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_ADC_Channel_Is_Calibration(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(ADC_Channel_Is_Calibration, 0664, show_ADC_Channel_Is_Calibration,
- store_ADC_Channel_Is_Calibration);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : Power_On_Voltage */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_Power_On_Voltage(struct device *dev, struct device_attribute *attr, char *buf)
- {
- int ret_value = 1;
- ret_value = 3400;
- battery_log(BAT_LOG_CRTI, "[EM] Power_On_Voltage : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_Power_On_Voltage(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(Power_On_Voltage, 0664, show_Power_On_Voltage, store_Power_On_Voltage);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : Power_Off_Voltage */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_Power_Off_Voltage(struct device *dev, struct device_attribute *attr, char *buf)
- {
- int ret_value = 1;
- ret_value = 3400;
- battery_log(BAT_LOG_CRTI, "[EM] Power_Off_Voltage : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_Power_Off_Voltage(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(Power_Off_Voltage, 0664, show_Power_Off_Voltage, store_Power_Off_Voltage);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : Charger_TopOff_Value */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_Charger_TopOff_Value(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 1;
- ret_value = 4110;
- battery_log(BAT_LOG_CRTI, "[EM] Charger_TopOff_Value : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_Charger_TopOff_Value(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(Charger_TopOff_Value, 0664, show_Charger_TopOff_Value,
- store_Charger_TopOff_Value);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : FG_Battery_CurrentConsumption */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_FG_Battery_CurrentConsumption(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- int ret_value = 8888;
- ret_value = battery_meter_get_battery_current();
- battery_log(BAT_LOG_CRTI, "[EM] FG_Battery_CurrentConsumption : %d/10 mA\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_FG_Battery_CurrentConsumption(struct device *dev,
- struct device_attribute *attr, const char *buf,
- size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(FG_Battery_CurrentConsumption, 0664, show_FG_Battery_CurrentConsumption,
- store_FG_Battery_CurrentConsumption);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Create File For EM : FG_SW_CoulombCounter */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static ssize_t show_FG_SW_CoulombCounter(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- s32 ret_value = 7777;
- ret_value = battery_meter_get_car();
- battery_log(BAT_LOG_CRTI, "[EM] FG_SW_CoulombCounter : %d\n", ret_value);
- return sprintf(buf, "%u\n", ret_value);
- }
- static ssize_t store_FG_SW_CoulombCounter(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- battery_log(BAT_LOG_CRTI, "[EM] Not Support Write Function\n");
- return size;
- }
- static DEVICE_ATTR(FG_SW_CoulombCounter, 0664, show_FG_SW_CoulombCounter,
- store_FG_SW_CoulombCounter);
- static ssize_t show_Charging_CallState(struct device *dev, struct device_attribute *attr, char *buf)
- {
- battery_log(BAT_LOG_CRTI, "call state = %d\n", g_call_state);
- return sprintf(buf, "%u\n", g_call_state);
- }
- static ssize_t store_Charging_CallState(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- int ret, call_state;
- ret = kstrtoint(buf, 0, &call_state);
- if (ret) {
- pr_err("wrong format!\n");
- return size;
- }
- g_call_state = (call_state ? true : false);
- battery_log(BAT_LOG_CRTI, "call state = %d\n", g_call_state);
- return size;
- }
- static DEVICE_ATTR(Charging_CallState, 0664, show_Charging_CallState, store_Charging_CallState);
- static ssize_t show_Charging_Enable(struct device *dev, struct device_attribute *attr, char *buf)
- {
- battery_log(BAT_LOG_CRTI, "hold charging = %d\n", g_cmd_hold_charging);
- return sprintf(buf, "%u\n", !g_cmd_hold_charging);
- }
- static ssize_t store_Charging_Enable(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- int ret, charging_enable = 1;
- ret = kstrtoint(buf, 0, &charging_enable);
- if (ret) {
- pr_err("wrong format!\n");
- return size;
- }
- if (charging_enable == 1)
- g_cmd_hold_charging = false;
- else if (charging_enable == 0)
- g_cmd_hold_charging = true;
- wake_up_bat_update_meter();
- battery_log(BAT_LOG_CRTI, "hold charging = %d\n", g_cmd_hold_charging);
- return size;
- }
- static DEVICE_ATTR(Charging_Enable, 0664, show_Charging_Enable, store_Charging_Enable);
- #if defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT)
- static ssize_t show_Pump_Express(struct device *dev, struct device_attribute *attr, char *buf)
- {
- int icount = 20; /* max debouncing time 20 * 0.2 sec */
- if (true == ta_check_chr_type && STANDARD_CHARGER == BMT_status.charger_type &&
- BMT_status.SOC >= p_bat_charging_data->ta_start_battery_soc &&
- BMT_status.SOC < p_bat_charging_data->ta_stop_battery_soc) {
- battery_log(BAT_LOG_CRTI, "[%s]Wait for PE detection\n", __func__);
- do {
- icount--;
- msleep(200);
- } while (icount && ta_check_chr_type);
- }
- battery_log(BAT_LOG_CRTI, "Pump express = %d\n", is_ta_connect);
- return sprintf(buf, "%u\n", is_ta_connect);
- }
- static ssize_t store_Pump_Express(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- int rv;
- u32 value;
- rv = kstrtouint(buf, 0, &value);
- if (rv != 1)
- return -EINVAL;
- is_ta_connect = (value != 0) ? true : false;
- battery_log(BAT_LOG_CRTI, "Pump express= %d\n", is_ta_connect);
- return size;
- }
- static DEVICE_ATTR(Pump_Express, 0664, show_Pump_Express, store_Pump_Express);
- #endif
- static ssize_t show_Custom_Charging_Current(struct device *dev, struct device_attribute *attr,
- char *buf)
- {
- battery_log(BAT_LOG_CRTI, "custom charging current = %d\n", g_custom_charging_current);
- return sprintf(buf, "%d\n", g_custom_charging_current);
- }
- static ssize_t store_Custom_Charging_Current(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- int ret, cur;
- ret = kstrtoint(buf, 0, &cur);
- if (ret) {
- pr_err("wrong format!\n");
- return size;
- }
- g_custom_charging_current = cur;
- battery_log(BAT_LOG_CRTI, "custom charging current = %d\n", g_custom_charging_current);
- wake_up_bat_update_meter();
- return size;
- }
- static DEVICE_ATTR(Custom_Charging_Current, 0664, show_Custom_Charging_Current,
- store_Custom_Charging_Current);
- static void mt_battery_update_EM(struct battery_data *bat_data)
- {
- bat_data->BAT_CAPACITY = BMT_status.UI_SOC;
- bat_data->BAT_TemperatureR = BMT_status.temperatureR; /* API */
- bat_data->BAT_TempBattVoltage = BMT_status.temperatureV; /* API */
- bat_data->BAT_InstatVolt = BMT_status.bat_vol; /* VBAT */
- bat_data->BAT_BatteryAverageCurrent = BMT_status.ICharging;
- bat_data->BAT_BatterySenseVoltage = BMT_status.bat_vol;
- bat_data->BAT_ISenseVoltage = BMT_status.Vsense; /* API */
- bat_data->BAT_ChargerVoltage = BMT_status.charger_vol;
- if ((BMT_status.UI_SOC == 100) && BMT_status.charger_exist)
- bat_data->BAT_STATUS = POWER_SUPPLY_STATUS_FULL;
- #ifdef CONFIG_MTK_DISABLE_POWER_ON_OFF_VOLTAGE_LIMITATION
- if (bat_data->BAT_CAPACITY <= 0)
- bat_data->BAT_CAPACITY = 1;
- battery_log(BAT_LOG_CRTI,
- "BAT_CAPACITY=1, due to define MTK_DISABLE_POWER_ON_OFF_VOLTAGE_LIMITATION\r\n");
- #endif
- }
- static bool mt_battery_100Percent_tracking_check(void)
- {
- bool resetBatteryMeter = false;
- u32 cust_sync_time;
- static u32 timer_counter;
- #if defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT)
- cust_sync_time = p_bat_charging_data->cust_soc_jeita_sync_time;
- if (timer_counter == 0)
- timer_counter = (cust_sync_time / BAT_TASK_PERIOD);
- #else
- cust_sync_time = p_bat_charging_data->onehundred_percent_tracking_time;
- if (timer_counter == 0)
- timer_counter = (cust_sync_time / BAT_TASK_PERIOD);
- #endif
- #if defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT)
- if (g_temp_status != TEMP_POS_10_TO_POS_45 && g_temp_status != TEMP_POS_0_TO_POS_10) {
- battery_log(BAT_LOG_FULL,
- "Skip 100percent tracking due to not 4.2V full-charging.\n");
- return false;
- }
- #endif
- if (BMT_status.bat_full == true) { /* charging full first, UI tracking to 100% */
- if (BMT_status.bat_in_recharging_state == true) {
- if (BMT_status.UI_SOC >= 100)
- BMT_status.UI_SOC = 100;
- resetBatteryMeter = false;
- } else if (BMT_status.UI_SOC >= 100) {
- BMT_status.UI_SOC = 100;
- if ((g_charging_full_reset_bat_meter == true)
- && (BMT_status.bat_charging_state == CHR_BATFULL)) {
- resetBatteryMeter = true;
- g_charging_full_reset_bat_meter = false;
- } else {
- resetBatteryMeter = false;
- }
- } else {
- /* increase UI percentage every xxs */
- if (timer_counter >= (cust_sync_time / BAT_TASK_PERIOD)) {
- timer_counter = 1;
- BMT_status.UI_SOC++;
- } else {
- timer_counter++;
- return resetBatteryMeter;
- }
- resetBatteryMeter = true;
- }
- battery_log(BAT_LOG_FULL,
- "[Battery] mt_battery_100percent_tracking(), Charging full first UI(%d), reset(%d) \r\n",
- BMT_status.UI_SOC, resetBatteryMeter);
- } else {
- /* charging is not full, UI keep 99% if reaching 100%, */
- if (BMT_status.UI_SOC >= 99 && battery_meter_get_battery_current_sign()) {
- BMT_status.UI_SOC = 99;
- resetBatteryMeter = true;
- battery_log(BAT_LOG_FULL,
- "[Battery] mt_battery_100percent_tracking(), UI full first, keep (%d) \r\n",
- BMT_status.UI_SOC);
- }
- timer_counter = (cust_sync_time / BAT_TASK_PERIOD);
- }
- return resetBatteryMeter;
- }
- static bool mt_battery_nPercent_tracking_check(void)
- {
- bool resetBatteryMeter = false;
- #if defined(CONFIG_SOC_BY_HW_FG)
- static u32 timer_counter;
- if (timer_counter == 0)
- timer_counter = (p_bat_charging_data->npercent_tracking_time / BAT_TASK_PERIOD);
- if (BMT_status.nPrecent_UI_SOC_check_point == 0)
- return false;
- /* fuel gauge ZCV < 15%, but UI > 15%, 15% can be customized */
- if ((BMT_status.ZCV <= BMT_status.nPercent_ZCV)
- && (BMT_status.UI_SOC > BMT_status.nPrecent_UI_SOC_check_point)) {
- if (timer_counter ==
- (p_bat_charging_data->npercent_tracking_time / BAT_TASK_PERIOD)) {
- BMT_status.UI_SOC--; /* every x sec decrease UI percentage */
- timer_counter = 1;
- } else {
- timer_counter++;
- return resetBatteryMeter;
- }
- resetBatteryMeter = true;
- battery_log(BAT_LOG_CRTI,
- "[Battery]mt_battery_nPercent_tracking_check(), ZCV(%d) <= BMT_status.nPercent_ZCV(%d), UI_SOC=%d., tracking UI_SOC=%d \r\n",
- BMT_status.ZCV, BMT_status.nPercent_ZCV, BMT_status.UI_SOC,
- BMT_status.nPrecent_UI_SOC_check_point);
- } else if ((BMT_status.ZCV > BMT_status.nPercent_ZCV)
- && (BMT_status.UI_SOC == BMT_status.nPrecent_UI_SOC_check_point)) {
- /* UI less than 15 , but fuel gague is more than 15, hold UI 15% */
- timer_counter = (p_bat_charging_data->npercent_tracking_time / BAT_TASK_PERIOD);
- resetBatteryMeter = true;
- battery_log(BAT_LOG_CRTI,
- "[Battery]mt_battery_nPercent_tracking_check() ZCV(%d) > BMT_status.nPercent_ZCV(%d) and UI SOC (%d), then keep %d. \r\n",
- BMT_status.ZCV, BMT_status.nPercent_ZCV, BMT_status.UI_SOC,
- BMT_status.nPrecent_UI_SOC_check_point);
- } else {
- timer_counter = (p_bat_charging_data->npercent_tracking_time / BAT_TASK_PERIOD);
- }
- #endif
- return resetBatteryMeter;
- }
- static bool mt_battery_0Percent_tracking_check(void)
- {
- bool resetBatteryMeter = true;
- if (BMT_status.UI_SOC <= 0)
- BMT_status.UI_SOC = 0;
- else
- BMT_status.UI_SOC--;
- battery_log(BAT_LOG_CRTI,
- "[Battery] mt_battery_0Percent_tracking_check(), VBAT < %d UI_SOC = (%d)\r\n",
- SYSTEM_OFF_VOLTAGE, BMT_status.UI_SOC);
- return resetBatteryMeter;
- }
- static void mt_battery_Sync_UI_Percentage_to_Real(void)
- {
- static u32 timer_counter;
- if ((BMT_status.UI_SOC > BMT_status.SOC) && ((BMT_status.UI_SOC != 1))) {
- /* reduce after xxs */
- if (g_refresh_ui_soc
- || timer_counter ==
- (p_bat_charging_data->sync_to_real_tracking_time / BAT_TASK_PERIOD)) {
- BMT_status.UI_SOC--;
- timer_counter = 0;
- g_refresh_ui_soc = false;
- } else {
- timer_counter++;
- }
- battery_log(BAT_LOG_CRTI,
- "Sync UI percentage to Real one, BMT_status.UI_SOC=%d, BMT_status.SOC=%d, counter = %d\r\n",
- BMT_status.UI_SOC, BMT_status.SOC, timer_counter);
- } else {
- timer_counter = 0;
- if (BMT_status.UI_SOC == -1)
- BMT_status.UI_SOC = BMT_status.SOC;
- else if (BMT_status.charger_exist && BMT_status.bat_charging_state != CHR_ERROR) {
- if (BMT_status.UI_SOC < BMT_status.SOC
- && (BMT_status.SOC - BMT_status.UI_SOC > 1))
- BMT_status.UI_SOC++;
- else
- BMT_status.UI_SOC = BMT_status.SOC;
- }
- }
- if (BMT_status.UI_SOC <= 0) {
- BMT_status.UI_SOC = 1;
- battery_log(BAT_LOG_CRTI, "[Battery]UI_SOC get 0 first (%d)\r\n",
- BMT_status.UI_SOC);
- }
- }
- static void battery_update(struct battery_data *bat_data)
- {
- struct power_supply *bat_psy = &bat_data->psy;
- bool resetBatteryMeter = false;
- bat_data->BAT_TECHNOLOGY = POWER_SUPPLY_TECHNOLOGY_LION;
- bat_data->BAT_HEALTH = POWER_SUPPLY_HEALTH_GOOD;
- bat_data->BAT_VOLTAGE_AVG = BMT_status.bat_vol * 1000;
- bat_data->BAT_VOLTAGE_NOW = BMT_status.bat_vol * 1000; /* voltage_now unit is microvolt */
- bat_data->BAT_TEMP = BMT_status.temperature * 10;
- bat_data->BAT_PRESENT = BMT_status.bat_exist;
- if (BMT_status.charger_exist && (BMT_status.bat_charging_state != CHR_ERROR)
- && !g_cmd_hold_charging) {
- if (BMT_status.bat_exist) { /* charging */
- if (BMT_status.bat_vol <= SYSTEM_OFF_VOLTAGE)
- resetBatteryMeter = mt_battery_0Percent_tracking_check();
- else
- resetBatteryMeter = mt_battery_100Percent_tracking_check();
- bat_data->BAT_STATUS = POWER_SUPPLY_STATUS_CHARGING;
- } else { /* No Battery, Only Charger */
- bat_data->BAT_STATUS = POWER_SUPPLY_STATUS_UNKNOWN;
- BMT_status.UI_SOC = 0;
- }
- } else { /* Only Battery */
- bat_data->BAT_STATUS = POWER_SUPPLY_STATUS_DISCHARGING;
- if (BMT_status.bat_vol <= SYSTEM_OFF_VOLTAGE)
- resetBatteryMeter = mt_battery_0Percent_tracking_check();
- else
- resetBatteryMeter = mt_battery_nPercent_tracking_check();
- }
- if (resetBatteryMeter == true)
- battery_meter_reset(true);
- else
- mt_battery_Sync_UI_Percentage_to_Real();
- battery_log(BAT_LOG_FULL, "UI_SOC=(%d), resetBatteryMeter=(%d)\n",
- BMT_status.UI_SOC, resetBatteryMeter);
- #ifdef CUST_CAPACITY_OCV2CV_TRANSFORM
- /* We store capacity before loading compenstation in RTC */
- if (battery_meter_get_battery_soc() <= 1)
- set_rtc_spare_fg_value(1);
- else
- set_rtc_spare_fg_value(battery_meter_get_battery_soc()); /*use battery_soc */
- #else
- /* set RTC SOC to 1 to avoid SOC jump in charger boot. */
- if (BMT_status.UI_SOC <= 1)
- set_rtc_spare_fg_value(1);
- else
- set_rtc_spare_fg_value(BMT_status.UI_SOC);
- #endif
- battery_log(BAT_LOG_FULL, "RTC_SOC=(%d)\n", get_rtc_spare_fg_value());
- mt_battery_update_EM(bat_data);
- power_supply_changed(bat_psy);
- }
- static void ac_update(struct ac_data *ac_data)
- {
- static int ac_status = -1;
- struct power_supply *ac_psy = &ac_data->psy;
- if (BMT_status.charger_exist) {
- if ((BMT_status.charger_type == NONSTANDARD_CHARGER) ||
- (BMT_status.charger_type == STANDARD_CHARGER) ||
- (BMT_status.charger_type == APPLE_1_0A_CHARGER) ||
- (BMT_status.charger_type == APPLE_2_1A_CHARGER)) {
- ac_data->AC_ONLINE = 1;
- ac_psy->type = POWER_SUPPLY_TYPE_MAINS;
- } else
- ac_data->AC_ONLINE = 0;
- } else {
- ac_data->AC_ONLINE = 0;
- }
- if (ac_status != ac_data->AC_ONLINE) {
- ac_status = ac_data->AC_ONLINE;
- power_supply_changed(ac_psy);
- }
- }
- static void usb_update(struct usb_data *usb_data)
- {
- static int usb_status = -1;
- struct power_supply *usb_psy = &usb_data->psy;
- if (BMT_status.charger_exist) {
- if ((BMT_status.charger_type == STANDARD_HOST) ||
- (BMT_status.charger_type == CHARGING_HOST)) {
- usb_data->USB_ONLINE = 1;
- usb_psy->type = POWER_SUPPLY_TYPE_USB;
- } else
- usb_data->USB_ONLINE = 0;
- } else {
- usb_data->USB_ONLINE = 0;
- }
- if (usb_status != usb_data->USB_ONLINE) {
- usb_status = usb_data->USB_ONLINE;
- power_supply_changed(usb_psy);
- }
- }
- #endif
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Battery Temprature Parameters and functions */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- bool pmic_chrdet_status(void)
- {
- if (upmu_is_chr_det() == true)
- return true;
- battery_log(BAT_LOG_CRTI, "[pmic_chrdet_status] No charger\r\n");
- return false;
- }
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Pulse Charging Algorithm */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- bool bat_is_charger_exist(void)
- {
- return bat_charger_get_detect_status();
- }
- bool bat_is_charging_full(void)
- {
- if ((BMT_status.bat_full == true) && (BMT_status.bat_in_recharging_state == false))
- return true;
- else
- return false;
- }
- u32 bat_get_ui_percentage(void)
- {
- /* for plugging out charger in recharge phase, using SOC as UI_SOC */
- if (chr_wake_up_bat == true)
- return BMT_status.SOC;
- else
- return BMT_status.UI_SOC;
- }
- /* Full state --> recharge voltage --> full state */
- u32 bat_is_recharging_phase(void)
- {
- if (BMT_status.bat_in_recharging_state || BMT_status.bat_full == true)
- return true;
- else
- return false;
- }
- unsigned long BAT_Get_Battery_Voltage(int polling_mode)
- {
- unsigned long ret_val = 0;
- #if defined(CONFIG_POWER_EXT)
- ret_val = 4000;
- #else
- ret_val = battery_meter_get_battery_voltage();
- #endif
- return ret_val;
- }
- static void mt_battery_average_method_init(u32 *bufferdata, u32 data, s32 *sum)
- {
- u32 i;
- static bool batteryBufferFirst = true;
- static bool previous_charger_exist;
- static bool previous_in_recharge_state;
- static u8 index;
- /* reset charging current window while plug in/out */
- if (need_clear_current_window) {
- if (BMT_status.charger_exist) {
- if (previous_charger_exist == false) {
- batteryBufferFirst = true;
- previous_charger_exist = true;
- if ((BMT_status.charger_type == STANDARD_CHARGER)
- || (BMT_status.charger_type == APPLE_1_0A_CHARGER)
- || (BMT_status.charger_type == APPLE_2_1A_CHARGER)
- || (BMT_status.charger_type == CHARGING_HOST))
- data = 650; /* mA */
- else /* USB or non-stadanrd charger */
- data = 450; /* mA */
- } else if ((previous_in_recharge_state == false)
- && (BMT_status.bat_in_recharging_state == true)) {
- batteryBufferFirst = true;
- if ((BMT_status.charger_type == STANDARD_CHARGER)
- || (BMT_status.charger_type == APPLE_1_0A_CHARGER)
- || (BMT_status.charger_type == APPLE_2_1A_CHARGER)
- || (BMT_status.charger_type == CHARGING_HOST))
- data = 650; /* mA */
- else /* USB or non-stadanrd charger */
- data = 450; /* mA */
- }
- previous_in_recharge_state = BMT_status.bat_in_recharging_state;
- } else {
- if (previous_charger_exist == true) {
- batteryBufferFirst = true;
- previous_charger_exist = false;
- data = 0;
- }
- }
- }
- battery_log(BAT_LOG_FULL, "batteryBufferFirst =%d, data= (%d)\n", batteryBufferFirst, data);
- if (batteryBufferFirst == true) {
- for (i = 0; i < BATTERY_AVERAGE_SIZE; i++)
- bufferdata[i] = data;
- *sum = data * BATTERY_AVERAGE_SIZE;
- }
- index++;
- if (index >= BATTERY_AVERAGE_DATA_NUMBER) {
- index = BATTERY_AVERAGE_DATA_NUMBER;
- batteryBufferFirst = false;
- }
- }
- static u32 mt_battery_average_method(u32 *bufferdata, u32 data, s32 *sum, u8 batteryIndex)
- {
- u32 avgdata;
- mt_battery_average_method_init(bufferdata, data, sum);
- *sum -= bufferdata[batteryIndex];
- *sum += data;
- bufferdata[batteryIndex] = data;
- avgdata = (*sum) / BATTERY_AVERAGE_SIZE;
- battery_log(BAT_LOG_FULL, "bufferdata[%d]= (%d)\n", batteryIndex, bufferdata[batteryIndex]);
- return avgdata;
- }
- static int filter_battery_temperature(int instant_temp)
- {
- int check_count;
- /* recheck 3 times for critical temperature */
- for (check_count = 0; check_count < 3; check_count++) {
- if (instant_temp > p_bat_charging_data->max_discharge_temperature
- || instant_temp < p_bat_charging_data->min_discharge_temperature) {
- instant_temp = battery_meter_get_battery_temperature();
- pr_warn("recheck battery temperature result: %d\n", instant_temp);
- msleep(20);
- continue;
- }
- }
- return instant_temp;
- }
- void mt_battery_GetBatteryData(void)
- {
- u32 bat_vol, charger_vol, Vsense, ZCV;
- s32 ICharging, temperature, temperatureR, temperatureV, SOC;
- s32 avg_temperature;
- static s32 bat_sum, icharging_sum, temperature_sum;
- static s32 batteryVoltageBuffer[BATTERY_AVERAGE_SIZE];
- static s32 batteryCurrentBuffer[BATTERY_AVERAGE_SIZE];
- static s32 batteryTempBuffer[BATTERY_AVERAGE_SIZE];
- static u8 batteryIndex;
- static s32 previous_SOC = -1;
- bat_vol = battery_meter_get_battery_voltage();
- Vsense = battery_meter_get_VSense();
- ICharging = battery_meter_get_charging_current();
- charger_vol = battery_meter_get_charger_voltage();
- temperature = battery_meter_get_battery_temperature();
- temperatureV = battery_meter_get_tempV();
- temperatureR = battery_meter_get_tempR(temperatureV);
- if (bat_meter_timeout == true) {
- SOC = battery_meter_get_battery_percentage();
- bat_meter_timeout = false;
- } else {
- if (previous_SOC == -1)
- SOC = battery_meter_get_battery_percentage();
- else
- SOC = previous_SOC;
- }
- ZCV = battery_meter_get_battery_zcv();
- need_clear_current_window = true;
- BMT_status.ICharging =
- mt_battery_average_method(&batteryCurrentBuffer[0], ICharging, &icharging_sum,
- batteryIndex);
- need_clear_current_window = false;
- #if 1
- if (previous_SOC == -1 && bat_vol <= SYSTEM_OFF_VOLTAGE) {
- battery_log(BAT_LOG_CRTI,
- "battery voltage too low, use ZCV to init average data.\n");
- BMT_status.bat_vol =
- mt_battery_average_method(&batteryVoltageBuffer[0], ZCV, &bat_sum,
- batteryIndex);
- } else {
- BMT_status.bat_vol =
- mt_battery_average_method(&batteryVoltageBuffer[0], bat_vol, &bat_sum,
- batteryIndex);
- }
- #else
- BMT_status.bat_vol =
- mt_battery_average_method(&batteryVoltageBuffer[0], bat_vol, &bat_sum, batteryIndex);
- #endif
- avg_temperature =
- mt_battery_average_method(&batteryTempBuffer[0], temperature, &temperature_sum,
- batteryIndex);
- if (p_bat_charging_data->use_avg_temperature)
- BMT_status.temperature = avg_temperature;
- else
- BMT_status.temperature = filter_battery_temperature(temperature);
- if ((g_battery_thermal_throttling_flag == 1) || (g_battery_thermal_throttling_flag == 3)) {
- if (battery_cmd_thermal_test_mode == 1) {
- BMT_status.temperature = battery_cmd_thermal_test_mode_value;
- battery_log(BAT_LOG_FULL,
- "[Battery] In thermal_test_mode , Tbat=%d\n",
- BMT_status.temperature);
- }
- #if defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT)
- if (BMT_status.temperature > p_bat_charging_data->max_discharge_temperature
- || BMT_status.temperature < p_bat_charging_data->min_discharge_temperature) {
- struct battery_data *bat_data = &battery_main;
- struct power_supply *bat_psy = &bat_data->psy;
- pr_warn("[Battery] instant Tbat(%d) out of range, power down device.\n",
- BMT_status.temperature);
- bat_data->BAT_CAPACITY = 0;
- power_supply_changed(bat_psy);
- /* can not power down due to charger exist, so need reset system */
- if (BMT_status.charger_exist)
- bat_charger_set_platform_reset();
- else
- orderly_poweroff(true);
- }
- #endif
- }
- BMT_status.Vsense = Vsense;
- BMT_status.charger_vol = charger_vol;
- BMT_status.temperatureV = temperatureV;
- BMT_status.temperatureR = temperatureR;
- BMT_status.SOC = SOC;
- BMT_status.ZCV = ZCV;
- #ifndef CUST_CAPACITY_OCV2CV_TRANSFORM
- if (BMT_status.charger_exist == false) {
- if (BMT_status.SOC > previous_SOC && previous_SOC >= 0)
- BMT_status.SOC = previous_SOC;
- }
- #endif
- previous_SOC = BMT_status.SOC;
- batteryIndex++;
- if (batteryIndex >= BATTERY_AVERAGE_SIZE)
- batteryIndex = 0;
- battery_log(BAT_LOG_CRTI,
- "AvgVbat=(%d),bat_vol=(%d),AvgI=(%d),I=(%d),VChr=(%d),AvgT=(%d),T=(%d),pre_SOC=(%d),SOC=(%d),ZCV=(%d)\n",
- BMT_status.bat_vol, bat_vol, BMT_status.ICharging, ICharging,
- BMT_status.charger_vol, BMT_status.temperature, temperature,
- previous_SOC, BMT_status.SOC, BMT_status.ZCV);
- }
- static int mt_battery_CheckBatteryTemp(void)
- {
- int status = PMU_STATUS_OK;
- #if defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT)
- battery_log(BAT_LOG_CRTI, "[BATTERY] support JEITA, temperature=%d\n",
- BMT_status.temperature);
- if (do_jeita_state_machine() == PMU_STATUS_FAIL) {
- battery_log(BAT_LOG_CRTI, "[BATTERY] JEITA : fail\n");
- status = PMU_STATUS_FAIL;
- }
- #else
- #ifdef CONFIG_BAT_LOW_TEMP_PROTECT_ENABLE
- if ((BMT_status.temperature < p_bat_charging_data->min_charge_temperature)
- || (BMT_status.temperature == p_bat_charging_data->err_charge_temperature)) {
- battery_log(BAT_LOG_CRTI, "[BATTERY] Battery Under Temperature or NTC fail !!\n\r");
- status = PMU_STATUS_FAIL;
- }
- #endif
- if (BMT_status.temperature >= p_bat_charging_data->max_charge_temperature) {
- battery_log(BAT_LOG_CRTI, "[BATTERY] Battery Over Temperature !!\n\r");
- status = PMU_STATUS_FAIL;
- }
- #endif
- return status;
- }
- static int mt_battery_CheckChargerVoltage(void)
- {
- int status = PMU_STATUS_OK;
- if (BMT_status.charger_exist) {
- if (p_bat_charging_data->v_charger_enable == 1) {
- if (BMT_status.charger_vol <= p_bat_charging_data->v_charger_min) {
- battery_log(BAT_LOG_CRTI, "[BATTERY]Charger under voltage!!\r\n");
- BMT_status.bat_charging_state = CHR_ERROR;
- status = PMU_STATUS_FAIL;
- }
- }
- if (BMT_status.charger_vol >= p_bat_charging_data->v_charger_max) {
- battery_log(BAT_LOG_CRTI, "[BATTERY]Charger over voltage !!\r\n");
- BMT_status.charger_protect_status = charger_OVER_VOL;
- BMT_status.bat_charging_state = CHR_ERROR;
- status = PMU_STATUS_FAIL;
- }
- }
- return status;
- }
- static int mt_battery_CheckChargingTime(void)
- {
- int status = PMU_STATUS_OK;
- if ((g_battery_thermal_throttling_flag == 2) || (g_battery_thermal_throttling_flag == 3)) {
- battery_log(BAT_LOG_CRTI,
- "[TestMode] Disable Safety Timer. bat_tt_enable=%d, bat_thr_test_mode=%d, bat_thr_test_value=%d\n",
- g_battery_thermal_throttling_flag,
- battery_cmd_thermal_test_mode, battery_cmd_thermal_test_mode_value);
- } else {
- /* Charging OT */
- if (BMT_status.total_charging_time >= MAX_CHARGING_TIME) {
- battery_log(BAT_LOG_CRTI, "[BATTERY] Charging Over Time.\n");
- status = PMU_STATUS_FAIL;
- }
- }
- return status;
- }
- #if defined(CONFIG_STOP_CHARGING_IN_TAKLING)
- static int mt_battery_CheckCallState(void)
- {
- int status = PMU_STATUS_OK;
- if ((g_call_state == CALL_ACTIVE)
- && (BMT_status.bat_vol > p_bat_charging_data->v_cc2topoff_thres))
- status = PMU_STATUS_FAIL;
- return status;
- }
- #endif
- static void mt_battery_CheckBatteryStatus(void)
- {
- if (mt_battery_CheckBatteryTemp() != PMU_STATUS_OK) {
- BMT_status.bat_charging_state = CHR_ERROR;
- return;
- }
- if (mt_battery_CheckChargerVoltage() != PMU_STATUS_OK) {
- BMT_status.bat_charging_state = CHR_ERROR;
- return;
- }
- #if defined(CONFIG_STOP_CHARGING_IN_TAKLING)
- if (mt_battery_CheckCallState() != PMU_STATUS_OK) {
- BMT_status.bat_charging_state = CHR_HOLD;
- return;
- }
- #endif
- if (mt_battery_CheckChargingTime() != PMU_STATUS_OK) {
- BMT_status.bat_charging_state = CHR_ERROR;
- return;
- }
- if (g_cmd_hold_charging == true) {
- BMT_status.bat_charging_state = CHR_CMD_HOLD;
- return;
- } else if (BMT_status.bat_charging_state == CHR_CMD_HOLD) {
- BMT_status.bat_charging_state = CHR_PRE;
- return;
- }
- }
- static void mt_battery_notify_TatalChargingTime_check(void)
- {
- #if defined(BATTERY_NOTIFY_CASE_0005_TOTAL_CHARGINGTIME)
- if ((g_battery_thermal_throttling_flag == 2) || (g_battery_thermal_throttling_flag == 3)) {
- battery_log(BAT_LOG_CRTI, "[TestMode] Disable Safety Timer : no UI display\n");
- } else {
- if (BMT_status.total_charging_time >= MAX_CHARGING_TIME)
- /* if(BMT_status.total_charging_time >= 60) //test */
- {
- g_BatteryNotifyCode |= 0x0010;
- battery_log(BAT_LOG_CRTI, "[BATTERY] Charging Over Time\n");
- } else {
- g_BatteryNotifyCode &= ~(0x0010);
- }
- }
- battery_log(BAT_LOG_FULL,
- "[BATTERY] BATTERY_NOTIFY_CASE_0005_TOTAL_CHARGINGTIME (%x)\n",
- g_BatteryNotifyCode);
- #endif
- }
- static void mt_battery_notify_VBat_check(void)
- {
- #if defined(BATTERY_NOTIFY_CASE_0004_VBAT)
- if (BMT_status.bat_vol > 4350)
- /* if(BMT_status.bat_vol > 3800) //test */
- {
- g_BatteryNotifyCode |= 0x0008;
- battery_log(BAT_LOG_CRTI, "[BATTERY] bat_vlot(%d) > 4350mV\n", BMT_status.bat_vol);
- } else {
- g_BatteryNotifyCode &= ~(0x0008);
- }
- battery_log(BAT_LOG_FULL, "[BATTERY] BATTERY_NOTIFY_CASE_0004_VBAT (%x)\n",
- g_BatteryNotifyCode);
- #endif
- }
- static void mt_battery_notify_ICharging_check(void)
- {
- #if defined(BATTERY_NOTIFY_CASE_0003_ICHARGING)
- if ((BMT_status.ICharging > 1000) && (BMT_status.total_charging_time > 300)) {
- g_BatteryNotifyCode |= 0x0004;
- battery_log(BAT_LOG_CRTI, "[BATTERY] I_charging(%ld) > 1000mA\n",
- BMT_status.ICharging);
- } else {
- g_BatteryNotifyCode &= ~(0x0004);
- }
- battery_log(BAT_LOG_CRTI, "[BATTERY] BATTERY_NOTIFY_CASE_0003_ICHARGING (%x)\n",
- g_BatteryNotifyCode);
- #endif
- }
- static void mt_battery_notify_VBatTemp_check(void)
- {
- #if defined(BATTERY_NOTIFY_CASE_0002_VBATTEMP)
- #if defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT)
- if ((BMT_status.temperature >= p_bat_charging_data->max_charge_temperature)
- || (BMT_status.temperature < p_bat_charging_data->temp_neg_10_threshold)) {
- #else
- #ifdef CONFIG_BAT_LOW_TEMP_PROTECT_ENABLE
- if ((BMT_status.temperature >= p_bat_charging_data->max_charge_temperature)
- || (BMT_status.temperature < p_bat_charging_data->min_charge_temperature)) {
- #else
- if (BMT_status.temperature >= p_bat_charging_data->max_charge_temperature) {
- #endif
- #endif /* #if defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT) */
- g_BatteryNotifyCode |= 0x0002;
- battery_log(BAT_LOG_CRTI, "[BATTERY] bat_temp(%d) out of range\n",
- BMT_status.temperature);
- } else {
- g_BatteryNotifyCode &= ~(0x0002);
- }
- battery_log(BAT_LOG_CRTI, "[BATTERY] BATTERY_NOTIFY_CASE_0002_VBATTEMP (%x)\n",
- g_BatteryNotifyCode);
- #endif
- }
- static void mt_battery_notify_VCharger_check(void)
- {
- #if defined(BATTERY_NOTIFY_CASE_0001_VCHARGER)
- if (BMT_status.charger_vol > p_bat_charging_data->v_charger_max) {
- g_BatteryNotifyCode |= 0x0001;
- battery_log(BAT_LOG_CRTI, "[BATTERY] BMT_status.charger_vol(%d) > %d mV\n",
- BMT_status.charger_vol, p_bat_charging_data->v_charger_max);
- } else {
- g_BatteryNotifyCode &= ~(0x0001);
- }
- battery_log(BAT_LOG_FULL, "[BATTERY] BATTERY_NOTIFY_CASE_0001_VCHARGER (%x)\n",
- g_BatteryNotifyCode);
- #endif
- }
- static void mt_battery_notify_UI_test(void)
- {
- if (g_BN_TestMode == 0x0001) {
- g_BatteryNotifyCode = 0x0001;
- battery_log(BAT_LOG_CRTI, "[BATTERY_TestMode] BATTERY_NOTIFY_CASE_0001_VCHARGER\n");
- } else if (g_BN_TestMode == 0x0002) {
- g_BatteryNotifyCode = 0x0002;
- battery_log(BAT_LOG_CRTI, "[BATTERY_TestMode] BATTERY_NOTIFY_CASE_0002_VBATTEMP\n");
- } else if (g_BN_TestMode == 0x0003) {
- g_BatteryNotifyCode = 0x0004;
- battery_log(BAT_LOG_CRTI,
- "[BATTERY_TestMode] BATTERY_NOTIFY_CASE_0003_ICHARGING\n");
- } else if (g_BN_TestMode == 0x0004) {
- g_BatteryNotifyCode = 0x0008;
- battery_log(BAT_LOG_CRTI, "[BATTERY_TestMode] BATTERY_NOTIFY_CASE_0004_VBAT\n");
- } else if (g_BN_TestMode == 0x0005) {
- g_BatteryNotifyCode = 0x0010;
- battery_log(BAT_LOG_CRTI,
- "[BATTERY_TestMode] BATTERY_NOTIFY_CASE_0005_TOTAL_CHARGINGTIME\n");
- } else {
- battery_log(BAT_LOG_CRTI, "[BATTERY] Unknown BN_TestMode Code : %x\n",
- g_BN_TestMode);
- }
- }
- void mt_battery_notify_check(void)
- {
- g_BatteryNotifyCode = 0x0000;
- if (g_BN_TestMode == 0x0000) { /* for normal case */
- battery_log(BAT_LOG_FULL, "[BATTERY] mt_battery_notify_check\n");
- mt_battery_notify_VCharger_check();
- mt_battery_notify_VBatTemp_check();
- mt_battery_notify_ICharging_check();
- mt_battery_notify_VBat_check();
- mt_battery_notify_TatalChargingTime_check();
- } else { /* for UI test */
- mt_battery_notify_UI_test();
- }
- }
- static void mt_battery_thermal_check(void)
- {
- if ((g_battery_thermal_throttling_flag == 1) || (g_battery_thermal_throttling_flag == 3)) {
- if (battery_cmd_thermal_test_mode == 1) {
- BMT_status.temperature = battery_cmd_thermal_test_mode_value;
- battery_log(BAT_LOG_FULL,
- "[Battery] In thermal_test_mode , Tbat=%d\n",
- BMT_status.temperature);
- }
- #if defined(CONFIG_MTK_JEITA_STANDARD_SUPPORT)
- if (BMT_status.temperature > p_bat_charging_data->max_discharge_temperature
- || BMT_status.temperature < p_bat_charging_data->min_discharge_temperature) {
- struct battery_data *bat_data = &battery_main;
- struct power_supply *bat_psy = &bat_data->psy;
- pr_warn("[Battery] Tbat(%d)out of range, power down device.\n",
- BMT_status.temperature);
- bat_data->BAT_CAPACITY = 0;
- power_supply_changed(bat_psy);
- /* can not power down due to charger exist, so need reset system */
- if (BMT_status.charger_exist)
- bat_charger_set_platform_reset();
- else
- orderly_poweroff(true);
- }
- #else
- if (BMT_status.temperature >= p_bat_charging_data->max_discharge_temperature) {
- #if defined(CONFIG_POWER_EXT)
- battery_log(BAT_LOG_CRTI,
- "[BATTERY] CONFIG_POWER_EXT, no update battery update power down.\n");
- #else
- {
- if ((g_platform_boot_mode == META_BOOT)
- || (g_platform_boot_mode == ADVMETA_BOOT)
- || (g_platform_boot_mode == ATE_FACTORY_BOOT)) {
- battery_log(BAT_LOG_FULL,
- "[BATTERY] boot mode = %d, bypass temperature check\n",
- g_platform_boot_mode);
- } else {
- struct battery_data *bat_data = &battery_main;
- struct power_supply *bat_psy = &bat_data->psy;
- battery_log(BAT_LOG_ERROR,
- "[Battery] Tbat(%d)>=%d, system need power down.\n",
- p_bat_charging_data->max_discharge_temperature,
- BMT_status.temperature);
- bat_data->BAT_CAPACITY = 0;
- power_supply_changed(bat_psy);
- /* can not power down due to charger exist, so need reset system */
- if (BMT_status.charger_exist)
- bat_charger_set_platform_reset();
- else
- orderly_poweroff(true);
- }
- }
- #endif
- }
- #endif
- }
- }
- int bat_charger_type_detection(void)
- {
- mutex_lock(&charger_type_mutex);
- if (BMT_status.charger_type == CHARGER_UNKNOWN)
- BMT_status.charger_type = bat_charger_get_charger_type();
- mutex_unlock(&charger_type_mutex);
- return BMT_status.charger_type;
- }
- static void mt_battery_charger_detect_check(void)
- {
- static bool fg_first_detect;
- if (upmu_is_chr_det() == true) {
- if (!BMT_status.charger_exist)
- wake_lock(&battery_suspend_lock);
- BMT_status.charger_exist = true;
- /* re-detect once after 10s if it is non-standard type */
- if (BMT_status.charger_type == NONSTANDARD_CHARGER && fg_first_detect) {
- mutex_lock(&charger_type_mutex);
- BMT_status.charger_type = bat_charger_get_charger_type();
- mutex_unlock(&charger_type_mutex);
- fg_first_detect = false;
- if (BMT_status.charger_type != NONSTANDARD_CHARGER)
- pr_warn("Update charger type to %d!\n", BMT_status.charger_type);
- }
- if (BMT_status.charger_type == CHARGER_UNKNOWN) {
- bat_charger_type_detection();
- if ((BMT_status.charger_type == STANDARD_HOST)
- || (BMT_status.charger_type == CHARGING_HOST)) {
- mt_usb_connect();
- }
- if (BMT_status.charger_type != CHARGER_UNKNOWN)
- fg_first_detect = true;
- }
- battery_log(BAT_LOG_FULL, "[BAT_thread]Cable in, CHR_Type_num=%d\r\n",
- BMT_status.charger_type);
- } else {
- if (BMT_status.charger_exist)
- wake_lock_timeout(&battery_suspend_lock, HZ / 2);
- fg_first_detect = false;
- BMT_status.charger_exist = false;
- BMT_status.charger_type = CHARGER_UNKNOWN;
- BMT_status.bat_full = false;
- BMT_status.bat_in_recharging_state = false;
- BMT_status.bat_charging_state = CHR_PRE;
- BMT_status.total_charging_time = 0;
- BMT_status.PRE_charging_time = 0;
- BMT_status.CC_charging_time = 0;
- BMT_status.TOPOFF_charging_time = 0;
- BMT_status.POSTFULL_charging_time = 0;
- #ifdef CONFIG_MTK_KERNEL_POWER_OFF_CHARGING
- if (g_platform_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT
- || g_platform_boot_mode == LOW_POWER_OFF_CHARGING_BOOT) {
- pr_warn
- ("Unplug Charger/USB In Kernel Power Off Charging Mode! Shutdown OS!\r\n");
- orderly_poweroff(true);
- }
- #endif
- if (g_cmd_hold_charging) {
- g_cmd_hold_charging = false;
- bat_charger_enable_power_path(true);
- }
- battery_log(BAT_LOG_FULL, "[BAT_thread]Cable out \r\n");
- mt_usb_disconnect();
- }
- }
- static void mt_battery_update_status(void)
- {
- #if defined(CONFIG_POWER_EXT)
- battery_log(BAT_LOG_CRTI, "[BATTERY] CONFIG_POWER_EXT, no update Android.\n");
- #else
- {
- if (battery_meter_initilized == true)
- battery_update(&battery_main);
- ac_update(&ac_main);
- usb_update(&usb_main);
- }
- #endif
- }
- static void do_chrdet_int_task(void)
- {
- if (g_bat_init_flag == true) {
- if (upmu_is_chr_det() == true) {
- pr_debug("[do_chrdet_int_task] charger exist!\n");
- if (!BMT_status.charger_exist)
- wake_lock(&battery_suspend_lock);
- BMT_status.charger_exist = true;
- #if defined(CONFIG_POWER_EXT)
- bat_charger_type_detection();
- mt_usb_connect();
- battery_log(BAT_LOG_CRTI,
- "[do_chrdet_int_task] call mt_usb_connect() in EVB\n");
- #endif
- } else {
- pr_debug("[do_chrdet_int_task] charger NOT exist!\n");
- if (BMT_status.charger_exist) {
- if (g_platform_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT)
- wake_lock(&battery_suspend_lock);
- else
- wake_lock_timeout(&battery_suspend_lock, HZ / 2);
- }
- BMT_status.charger_exist = false;
- BMT_status.charger_type = CHARGER_UNKNOWN;
- #ifdef CONFIG_MTK_KERNEL_POWER_OFF_CHARGING
- if (g_platform_boot_mode == KERNEL_POWER_OFF_CHARGING_BOOT
- || g_platform_boot_mode == LOW_POWER_OFF_CHARGING_BOOT) {
- battery_log(BAT_LOG_CRTI,
- "[pmic_thread_kthread] Unplug Charger/USB In Kernel Power Off Charging Mode! Shutdown OS!\r\n");
- orderly_poweroff(true);
- }
- #endif
- #if defined(CONFIG_POWER_EXT)
- mt_usb_disconnect();
- battery_log(BAT_LOG_CRTI,
- "[do_chrdet_int_task] call mt_usb_disconnect() in EVB\n");
- #endif
- #if defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT)
- is_ta_connect = false;
- ta_check_chr_type = true;
- ta_cable_out_occur = true;
- #endif
- }
- if (BMT_status.UI_SOC == 100 && BMT_status.charger_exist) {
- BMT_status.bat_charging_state = CHR_BATFULL;
- BMT_status.bat_full = true;
- g_charging_full_reset_bat_meter = true;
- }
- mt_battery_update_status();
- wake_up_bat();
- } else {
- battery_log(BAT_LOG_CRTI,
- "[do_chrdet_int_task] battery thread not ready, will do after bettery init.\n");
- }
- }
- irqreturn_t ops_chrdet_int_handler(int irq, void *dev_id)
- {
- pr_debug("[Power/Battery][chrdet_bat_int_handler]....\n");
- do_chrdet_int_task();
- return IRQ_HANDLED;
- }
- void BAT_thread(void)
- {
- if (battery_meter_initilized == false) {
- battery_meter_initial(); /* move from battery_probe() to decrease booting time */
- BMT_status.nPercent_ZCV = battery_meter_get_battery_nPercent_zcv();
- battery_meter_initilized = true;
- }
- mt_battery_charger_detect_check();
- if (fg_battery_shutdown)
- return;
- mt_battery_GetBatteryData();
- if (fg_battery_shutdown)
- return;
- mt_battery_thermal_check();
- mt_battery_notify_check();
- if (BMT_status.charger_exist && !fg_battery_shutdown) {
- mt_battery_CheckBatteryStatus();
- mt_battery_charging_algorithm();
- }
- bat_charger_reset_watchdog_timer();
- mt_battery_update_status();
- }
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Internal API */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- int bat_thread_kthread(void *x)
- {
- ktime_t ktime = ktime_set(3, 0); /* 10s, 10* 1000 ms */
- /* Run on a process content */
- while (!fg_battery_shutdown) {
- int ret;
- mutex_lock(&bat_mutex);
- if (g_bat.init_done && !battery_suspended)
- BAT_thread();
- mutex_unlock(&bat_mutex);
- ret = wait_event_hrtimeout(bat_thread_wq, atomic_read(&bat_thread_wakeup), ktime);
- if (ret == -ETIME)
- bat_meter_timeout = true;
- else
- atomic_dec(&bat_thread_wakeup);
- pr_debug("%s: waking up: on %s; wake_flag=%d\n",
- __func__, ret == -ETIME ? "timer" : "event",
- atomic_read(&bat_thread_wakeup));
- if (!fg_battery_shutdown)
- ktime = ktime_set(BAT_TASK_PERIOD, 0); /* 10s, 10* 1000 ms */
- if (chr_wake_up_bat == true) { /* for charger plug in/ out */
- if (g_bat.init_done)
- battery_meter_reset(false);
- chr_wake_up_bat = false;
- battery_log(BAT_LOG_CRTI,
- "[BATTERY] Charger plug in/out, Call battery_meter_reset. (%d)\n",
- BMT_status.UI_SOC);
- }
- }
- mutex_lock(&bat_mutex);
- g_bat.down = true;
- mutex_unlock(&bat_mutex);
- return 0;
- }
- /*
- * This is charger interface to USB OTG code.
- * If OTG is host, charger functionality, and charger interrupt
- * must be disabled
- * */
- void bat_detect_set_usb_host_mode(bool usb_host_mode)
- {
- mutex_lock(&bat_mutex);
- /* Don't change the charger event state
- * if charger logic is not running */
- if (g_bat.init_done) {
- if (usb_host_mode && !g_bat.usb_host_mode)
- disable_irq(g_bat.irq);
- if (!usb_host_mode && g_bat.usb_host_mode)
- enable_irq(g_bat.irq);
- g_bat.usb_host_mode = usb_host_mode;
- }
- mutex_unlock(&bat_mutex);
- }
- EXPORT_SYMBOL(bat_detect_set_usb_host_mode);
- static int bat_setup_charger_locked(void)
- {
- int ret = -EAGAIN;
- if (g_bat.common_init_done && g_bat.charger && !g_bat.init_done) {
- /* AP:
- * Both common_battery and charger code are ready to go.
- * Finalize init of common_battery.
- */
- g_platform_boot_mode = bat_charger_get_platform_boot_mode();
- battery_log(BAT_LOG_CRTI, "[BAT_probe] g_platform_boot_mode = %d\n ",
- g_platform_boot_mode);
- /* AP:
- * MTK implementation requires that BAT_thread() be called at least once
- * before battery event is enabled.
- * Although this should not be necessary, we maintain compatibility
- * until rework is complete.
- */
- BAT_thread();
- g_bat.init_done = true;
- ret = irq_set_irq_wake(g_bat.irq, true);
- if (ret)
- pr_err("%s: irq_set_irq_wake err = %d\n", __func__, ret);
- enable_irq(g_bat.irq);
- pr_warn("%s: charger setup done\n", __func__);
- }
- /* if there is no external charger, we just enable detect irq */
- #if defined(CONFIG_POWER_EXT) && defined(NO_EXTERNAL_CHARGER)
- ret = irq_set_irq_wake(g_bat.irq, true);
- if (ret)
- pr_err("%s: irq_set_irq_wake err = %d\n", __func__, ret);
- enable_irq(g_bat.irq);
- pr_warn("%s: no charger. just enable detect irq.\n", __func__);
- #endif
- return ret;
- }
- int bat_charger_register(CHARGING_CONTROL ctrl)
- {
- int ret;
- mutex_lock(&bat_mutex);
- g_bat.charger = ctrl;
- ret = bat_setup_charger_locked();
- mutex_unlock(&bat_mutex);
- return ret;
- }
- EXPORT_SYMBOL(bat_charger_register);
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // fop API */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- static long adc_cali_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
- {
- int *user_data_addr;
- int *naram_data_addr;
- int i = 0;
- int ret = 0;
- int adc_in_data[2] = { 1, 1 };
- int adc_out_data[2] = { 1, 1 };
- mutex_lock(&bat_mutex);
- switch (cmd) {
- case TEST_ADC_CALI_PRINT:
- g_ADC_Cali = false;
- break;
- case SET_ADC_CALI_Slop:
- naram_data_addr = (int *)arg;
- ret = copy_from_user(adc_cali_slop, naram_data_addr, 36);
- g_ADC_Cali = false; /* enable calibration after setting ADC_CALI_Cal */
- /* Protection */
- for (i = 0; i < 14; i++) {
- if ((*(adc_cali_slop + i) == 0) || (*(adc_cali_slop + i) == 1))
- *(adc_cali_slop + i) = 1000;
- }
- /*
- for (i = 0; i < 14; i++)
- battery_log(BAT_LOG_CRTI, "adc_cali_slop[%d] = %d\n", i,
- *(adc_cali_slop + i));
- battery_log(BAT_LOG_FULL,
- "**** unlocked_ioctl : SET_ADC_CALI_Slop Done!\n");
- */
- break;
- case SET_ADC_CALI_Offset:
- naram_data_addr = (int *)arg;
- ret = copy_from_user(adc_cali_offset, naram_data_addr, 36);
- g_ADC_Cali = false; /* enable calibration after setting ADC_CALI_Cal */
- /*
- for (i = 0; i < 14; i++)
- battery_log(BAT_LOG_CRTI, "adc_cali_offset[%d] = %d\n", i,
- *(adc_cali_offset + i));
- battery_log(BAT_LOG_FULL,
- "**** unlocked_ioctl : SET_ADC_CALI_Offset Done!\n");
- */
- break;
- case SET_ADC_CALI_Cal:
- naram_data_addr = (int *)arg;
- ret = copy_from_user(adc_cali_cal, naram_data_addr, 4);
- g_ADC_Cali = true;
- if (adc_cali_cal[0] == 1)
- g_ADC_Cali = true;
- else
- g_ADC_Cali = false;
- for (i = 0; i < 1; i++)
- battery_log(BAT_LOG_CRTI, "adc_cali_cal[%d] = %d\n", i,
- *(adc_cali_cal + i));
- battery_log(BAT_LOG_FULL, "**** unlocked_ioctl : SET_ADC_CALI_Cal Done!\n");
- break;
- case ADC_CHANNEL_READ:
- /* g_ADC_Cali = false; // 20100508 Infinity */
- user_data_addr = (int *)arg;
- ret = copy_from_user(adc_in_data, user_data_addr, 8); /* 2*int = 2*4 */
- if (adc_in_data[0] == 0) /* I_SENSE */
- adc_out_data[0] = battery_meter_get_VSense() * adc_in_data[1];
- else if (adc_in_data[0] == 1) /* BAT_SENSE */
- adc_out_data[0] = battery_meter_get_battery_voltage() * adc_in_data[1];
- else if (adc_in_data[0] == 3) /* V_Charger */
- adc_out_data[0] = battery_meter_get_charger_voltage() * adc_in_data[1];
- else if (adc_in_data[0] == 30) /* V_Bat_temp magic number */
- adc_out_data[0] = battery_meter_get_battery_temperature() * adc_in_data[1];
- else if (adc_in_data[0] == 66) {
- adc_out_data[0] = (battery_meter_get_battery_current()) / 10;
- if (battery_meter_get_battery_current_sign() == true)
- adc_out_data[0] = 0 - adc_out_data[0]; /* charging */
- } else {
- battery_log(BAT_LOG_FULL, "unknown channel(%d,%d)\n",
- adc_in_data[0], adc_in_data[1]);
- }
- if (adc_out_data[0] < 0)
- adc_out_data[1] = 1; /* failed */
- else
- adc_out_data[1] = 0; /* success */
- if (adc_in_data[0] == 30)
- adc_out_data[1] = 0; /* success */
- if (adc_in_data[0] == 66)
- adc_out_data[1] = 0; /* success */
- ret = copy_to_user(user_data_addr, adc_out_data, 8);
- battery_log(BAT_LOG_CRTI,
- "**** unlocked_ioctl : Channel %d * %d times = %d\n",
- adc_in_data[0], adc_in_data[1], adc_out_data[0]);
- break;
- case BAT_STATUS_READ:
- user_data_addr = (int *)arg;
- ret = copy_from_user(battery_in_data, user_data_addr, 4);
- /* [0] is_CAL */
- if (g_ADC_Cali)
- battery_out_data[0] = 1;
- else
- battery_out_data[0] = 0;
- ret = copy_to_user(user_data_addr, battery_out_data, 4);
- battery_log(BAT_LOG_CRTI, "**** unlocked_ioctl : CAL:%d\n", battery_out_data[0]);
- break;
- case Set_Charger_Current: /* For Factory Mode */
- user_data_addr = (int *)arg;
- ret = copy_from_user(charging_level_data, user_data_addr, 4);
- g_ftm_battery_flag = true;
- if (charging_level_data[0] == 0)
- charging_level_data[0] = CHARGE_CURRENT_70_00_MA;
- else if (charging_level_data[0] == 1)
- charging_level_data[0] = CHARGE_CURRENT_200_00_MA;
- else if (charging_level_data[0] == 2)
- charging_level_data[0] = CHARGE_CURRENT_400_00_MA;
- else if (charging_level_data[0] == 3)
- charging_level_data[0] = CHARGE_CURRENT_450_00_MA;
- else if (charging_level_data[0] == 4)
- charging_level_data[0] = CHARGE_CURRENT_550_00_MA;
- else if (charging_level_data[0] == 5)
- charging_level_data[0] = CHARGE_CURRENT_650_00_MA;
- else if (charging_level_data[0] == 6)
- charging_level_data[0] = CHARGE_CURRENT_700_00_MA;
- else if (charging_level_data[0] == 7)
- charging_level_data[0] = CHARGE_CURRENT_800_00_MA;
- else if (charging_level_data[0] == 8)
- charging_level_data[0] = CHARGE_CURRENT_900_00_MA;
- else if (charging_level_data[0] == 9)
- charging_level_data[0] = CHARGE_CURRENT_1000_00_MA;
- else if (charging_level_data[0] == 10)
- charging_level_data[0] = CHARGE_CURRENT_1100_00_MA;
- else if (charging_level_data[0] == 11)
- charging_level_data[0] = CHARGE_CURRENT_1200_00_MA;
- else if (charging_level_data[0] == 12)
- charging_level_data[0] = CHARGE_CURRENT_1300_00_MA;
- else if (charging_level_data[0] == 13)
- charging_level_data[0] = CHARGE_CURRENT_1400_00_MA;
- else if (charging_level_data[0] == 14)
- charging_level_data[0] = CHARGE_CURRENT_1500_00_MA;
- else if (charging_level_data[0] == 15)
- charging_level_data[0] = CHARGE_CURRENT_1600_00_MA;
- else
- charging_level_data[0] = CHARGE_CURRENT_450_00_MA;
- wake_up_bat();
- battery_log(BAT_LOG_CRTI, "**** unlocked_ioctl : set_Charger_Current:%d\n",
- charging_level_data[0]);
- break;
- /* add for meta tool------------------------------- */
- case Get_META_BAT_VOL:
- user_data_addr = (int *)arg;
- ret = copy_from_user(adc_in_data, user_data_addr, 8);
- adc_out_data[0] = BMT_status.bat_vol;
- ret = copy_to_user(user_data_addr, adc_out_data, 8);
- break;
- case Get_META_BAT_SOC:
- user_data_addr = (int *)arg;
- ret = copy_from_user(adc_in_data, user_data_addr, 8);
- adc_out_data[0] = BMT_status.UI_SOC;
- ret = copy_to_user(user_data_addr, adc_out_data, 8);
- break;
- /* add bing meta tool------------------------------- */
- default:
- g_ADC_Cali = false;
- break;
- }
- mutex_unlock(&bat_mutex);
- return 0;
- }
- static int adc_cali_open(struct inode *inode, struct file *file)
- {
- return 0;
- }
- static int adc_cali_release(struct inode *inode, struct file *file)
- {
- return 0;
- }
- static const struct file_operations adc_cali_fops = {
- .owner = THIS_MODULE,
- .unlocked_ioctl = adc_cali_ioctl,
- .open = adc_cali_open,
- .release = adc_cali_release,
- };
- void check_battery_exist(void)
- {
- #if defined(CONFIG_CONFIG_DIS_CHECK_BATTERY)
- battery_log(BAT_LOG_FULL, "[BATTERY] Disable check battery exist.\n");
- #else
- u32 baton_count = 0;
- u32 i;
- for (i = 0; i < 3; i++)
- baton_count += bat_charger_get_battery_status();
- if (baton_count >= 3) {
- if ((g_platform_boot_mode == META_BOOT) || (g_platform_boot_mode == ADVMETA_BOOT)
- || (g_platform_boot_mode == ATE_FACTORY_BOOT)) {
- battery_log(BAT_LOG_FULL,
- "[BATTERY] boot mode = %d, bypass battery check\n",
- g_platform_boot_mode);
- } else {
- battery_log(BAT_LOG_FULL,
- "[BATTERY] Battery is not exist, power off FAN5405 and system (%d)\n",
- baton_count);
- bat_charger_enable(false);
- bat_charger_set_platform_reset();
- }
- }
- #endif
- }
- static void bat_parse_node(struct device_node *np, char *name, int *cust_val)
- {
- u32 val;
- if (of_property_read_u32(np, name, &val) == 0) {
- (*cust_val) = (int)val;
- pr_debug("%s get %s :%d\n", __func__, name, *cust_val);
- }
- }
- static void init_charging_data_from_dt(struct device_node *np)
- {
- bat_parse_node(np, "v_charger_max", &p_bat_charging_data->v_charger_max);
- bat_parse_node(np, "v_charger_min", &p_bat_charging_data->v_charger_min);
- bat_parse_node(np, "max_discharge_temperature", &p_bat_charging_data->max_discharge_temperature);
- bat_parse_node(np, "min_discharge_temperature", &p_bat_charging_data->min_discharge_temperature);
- bat_parse_node(np, "max_charge_temperature", &p_bat_charging_data->max_charge_temperature);
- bat_parse_node(np, "min_charge_temperature", &p_bat_charging_data->min_charge_temperature);
- bat_parse_node(np, "use_avg_temperature", &p_bat_charging_data->use_avg_temperature);
- bat_parse_node(np, "usb_charger_current", &p_bat_charging_data->usb_charger_current);
- bat_parse_node(np, "ac_charger_current", &p_bat_charging_data->ac_charger_current);
- bat_parse_node(np, "non_std_ac_charger_current", &p_bat_charging_data->non_std_ac_charger_current);
- bat_parse_node(np, "charging_host_charger_current", &p_bat_charging_data->charging_host_charger_current);
- bat_parse_node(np, "apple_0_5a_charger_current", &p_bat_charging_data->apple_0_5a_charger_current);
- bat_parse_node(np, "apple_1_0a_charger_current", &p_bat_charging_data->apple_1_0a_charger_current);
- bat_parse_node(np, "apple_2_1a_charger_current", &p_bat_charging_data->apple_2_1a_charger_current);
- bat_parse_node(np, "ta_start_battery_soc", &p_bat_charging_data->ta_start_battery_soc);
- bat_parse_node(np, "ta_stop_battery_soc", &p_bat_charging_data->ta_stop_battery_soc);
- bat_parse_node(np, "ta_ac_9v_input_current", &p_bat_charging_data->ta_ac_9v_input_current);
- bat_parse_node(np, "ta_ac_7v_input_current", &p_bat_charging_data->ta_ac_7v_input_current);
- bat_parse_node(np, "ta_ac_charging_current", &p_bat_charging_data->ta_ac_charging_current);
- bat_parse_node(np, "ta_9v_support", &p_bat_charging_data->ta_9v_support);
- bat_parse_node(np, "temp_pos_60_threshold", &p_bat_charging_data->temp_pos_60_threshold);
- bat_parse_node(np, "temp_pos_60_thres_minus_x_degree", &p_bat_charging_data->temp_pos_60_thres_minus_x_degree);
- bat_parse_node(np, "temp_pos_45_threshold", &p_bat_charging_data->temp_pos_45_threshold);
- bat_parse_node(np, "temp_pos_45_thres_minus_x_degree", &p_bat_charging_data->temp_pos_45_thres_minus_x_degree);
- bat_parse_node(np, "temp_pos_10_threshold", &p_bat_charging_data->temp_pos_10_threshold);
- bat_parse_node(np, "temp_pos_10_thres_plus_x_degree", &p_bat_charging_data->temp_pos_10_thres_plus_x_degree);
- bat_parse_node(np, "temp_pos_0_threshold ", &p_bat_charging_data->temp_pos_0_threshold);
- bat_parse_node(np, "temp_pos_0_thres_plus_x_degree", &p_bat_charging_data->temp_pos_0_thres_plus_x_degree);
- bat_parse_node(np, "temp_neg_10_threshold", &p_bat_charging_data->temp_neg_10_threshold);
- bat_parse_node(np, "temp_neg_10_thres_plus_x_degree",
- &p_bat_charging_data->temp_neg_10_thres_plus_x_degree);
- bat_parse_node(np, "jeita_temp_above_pos_60_cv_voltage ",
- &p_bat_charging_data->jeita_temp_above_pos_60_cv_voltage);
- bat_parse_node(np, "jeita_temp_pos_45_to_pos_60_cv_voltage",
- &p_bat_charging_data->jeita_temp_pos_45_to_pos_60_cv_voltage);
- bat_parse_node(np, "jeita_temp_pos_10_to_pos_45_cv_voltage",
- &p_bat_charging_data->jeita_temp_pos_10_to_pos_45_cv_voltage);
- bat_parse_node(np, "jeita_temp_pos_0_to_pos_10_cv_voltage",
- &p_bat_charging_data->jeita_temp_pos_0_to_pos_10_cv_voltage);
- bat_parse_node(np, "jeita_temp_neg_10_to_pos_0_cv_voltage",
- &p_bat_charging_data->jeita_temp_neg_10_to_pos_0_cv_voltage);
- bat_parse_node(np, "jeita_temp_below_neg_10_cv_voltage",
- &p_bat_charging_data->jeita_temp_below_neg_10_cv_voltage);
- }
- static int battery_probe(struct platform_device *pdev)
- {
- struct class_device *class_dev = NULL;
- struct device *dev = &pdev->dev;
- int ret = 0;
- pr_debug("******** battery driver probe!! ********\n");
- /* AP:
- * Use PMIC events as interrupts through kernel IRQ API.
- */
- atomic_set(&bat_thread_wakeup, 0);
- g_bat.irq = platform_get_irq(pdev, 0);
- if (g_bat.irq <= 0)
- return -EINVAL;
- p_bat_charging_data = (struct mt_battery_charging_custom_data *)dev_get_platdata(dev);
- if (!p_bat_charging_data) {
- pr_err("%s: no platform data. replace with default settings.\n", __func__);
- p_bat_charging_data = &default_charging_data;
- /* populate property here */
- init_charging_data_from_dt(pdev->dev.of_node);
- }
- irq_set_status_flags(g_bat.irq, IRQ_NOAUTOEN);
- ret = request_threaded_irq(g_bat.irq, NULL,
- ops_chrdet_int_handler,
- IRQF_TRIGGER_HIGH | IRQF_ONESHOT, "ops_mt6397_chrdet", pdev);
- if (ret) {
- pr_err("%s: request_threaded_irq err = %d\n", __func__, ret);
- return ret;
- }
- /* Integrate with NVRAM */
- ret = alloc_chrdev_region(&adc_cali_devno, 0, 1, ADC_CALI_DEVNAME);
- if (ret)
- battery_log(BAT_LOG_CRTI, "Error: Can't Get Major number for adc_cali\n");
- adc_cali_cdev = cdev_alloc();
- adc_cali_cdev->owner = THIS_MODULE;
- adc_cali_cdev->ops = &adc_cali_fops;
- ret = cdev_add(adc_cali_cdev, adc_cali_devno, 1);
- if (ret)
- battery_log(BAT_LOG_CRTI, "adc_cali Error: cdev_add\n");
- adc_cali_major = MAJOR(adc_cali_devno);
- adc_cali_class = class_create(THIS_MODULE, ADC_CALI_DEVNAME);
- class_dev = (struct class_device *)device_create(adc_cali_class,
- NULL,
- adc_cali_devno, NULL, ADC_CALI_DEVNAME);
- battery_log(BAT_LOG_CRTI, "[BAT_probe] adc_cali prepare : done !!\n ");
- wake_lock_init(&battery_suspend_lock, WAKE_LOCK_SUSPEND, "battery suspend wakelock");
- #if defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT)
- wake_lock_init(&TA_charger_suspend_lock, WAKE_LOCK_SUSPEND, "TA charger suspend wakelock");
- #endif
- /* Integrate with Android Battery Service */
- ret = power_supply_register(dev, &ac_main.psy);
- if (ret) {
- battery_log(BAT_LOG_CRTI, "[BAT_probe] power_supply_register AC Fail !!\n");
- return ret;
- }
- battery_log(BAT_LOG_CRTI, "[BAT_probe] power_supply_register AC Success !!\n");
- ret = power_supply_register(dev, &usb_main.psy);
- if (ret) {
- battery_log(BAT_LOG_CRTI, "[BAT_probe] power_supply_register USB Fail !!\n");
- return ret;
- }
- battery_log(BAT_LOG_CRTI, "[BAT_probe] power_supply_register USB Success !!\n");
- ret = power_supply_register(dev, &battery_main.psy);
- if (ret) {
- battery_log(BAT_LOG_CRTI, "[BAT_probe] power_supply_register Battery Fail !!\n");
- return ret;
- }
- battery_log(BAT_LOG_CRTI, "[BAT_probe] power_supply_register Battery Success !!\n");
- #if !defined(CONFIG_POWER_EXT)
- /* For EM */
- {
- int ret_device_file = 0;
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Charger_Voltage);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_0_Slope);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_1_Slope);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_2_Slope);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_3_Slope);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_4_Slope);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_5_Slope);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_6_Slope);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_7_Slope);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_8_Slope);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_9_Slope);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_10_Slope);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_11_Slope);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_12_Slope);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_13_Slope);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_0_Offset);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_1_Offset);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_2_Offset);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_3_Offset);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_4_Offset);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_5_Offset);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_6_Offset);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_7_Offset);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_8_Offset);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_9_Offset);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_10_Offset);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_11_Offset);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_12_Offset);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_13_Offset);
- ret_device_file = device_create_file(dev, &dev_attr_ADC_Channel_Is_Calibration);
- ret_device_file = device_create_file(dev, &dev_attr_Power_On_Voltage);
- ret_device_file = device_create_file(dev, &dev_attr_Power_Off_Voltage);
- ret_device_file = device_create_file(dev, &dev_attr_Charger_TopOff_Value);
- ret_device_file = device_create_file(dev, &dev_attr_FG_Battery_CurrentConsumption);
- ret_device_file = device_create_file(dev, &dev_attr_FG_SW_CoulombCounter);
- ret_device_file = device_create_file(dev, &dev_attr_Charging_CallState);
- ret_device_file = device_create_file(dev, &dev_attr_Charging_Enable);
- ret_device_file = device_create_file(dev, &dev_attr_Custom_Charging_Current);
- #if defined(CONFIG_MTK_PUMP_EXPRESS_PLUS_SUPPORT)
- ret_device_file = device_create_file(dev, &dev_attr_Pump_Express);
- #endif
- }
- /* battery_meter_initial(); //move to mt_battery_GetBatteryData() to decrease booting time */
- /* Initialization BMT Struct */
- BMT_status.bat_exist = true; /* phone must have battery */
- BMT_status.charger_exist = false; /* for default, no charger */
- BMT_status.bat_vol = 0;
- BMT_status.ICharging = 0;
- BMT_status.temperature = 0;
- BMT_status.charger_vol = 0;
- BMT_status.total_charging_time = 0;
- BMT_status.PRE_charging_time = 0;
- BMT_status.CC_charging_time = 0;
- BMT_status.TOPOFF_charging_time = 0;
- BMT_status.POSTFULL_charging_time = 0;
- BMT_status.SOC = 0;
- BMT_status.UI_SOC = -1;
- BMT_status.bat_charging_state = CHR_PRE;
- BMT_status.bat_in_recharging_state = false;
- BMT_status.bat_full = false;
- BMT_status.nPercent_ZCV = 0;
- BMT_status.nPrecent_UI_SOC_check_point = battery_meter_get_battery_nPercent_UI_SOC();
- kthread_run(bat_thread_kthread, NULL, "bat_thread_kthread");
- battery_log(BAT_LOG_CRTI, "[battery_probe] bat_thread_kthread Done\n");
- /*LOG System Set */
- init_proc_log();
- #endif
- g_bat_init_flag = true;
- mutex_lock(&bat_mutex);
- g_bat.common_init_done = true;
- bat_setup_charger_locked();
- mutex_unlock(&bat_mutex);
- return 0;
- }
- static int battery_remove(struct platform_device *dev)
- {
- battery_log(BAT_LOG_CRTI, "******** battery driver remove!! ********\n");
- return 0;
- }
- static void battery_shutdown(struct platform_device *pdev)
- {
- #if !defined(CONFIG_POWER_EXT)
- int count = 0;
- #endif
- pr_debug("******** battery driver shutdown!! ********\n");
- disable_irq(g_bat.irq);
- mutex_lock(&bat_mutex);
- fg_battery_shutdown = true;
- wake_up_bat_update_meter();
- #if !defined(CONFIG_POWER_EXT)
- while (!g_bat.down && count < 5) {
- mutex_unlock(&bat_mutex);
- msleep(20);
- count++;
- mutex_lock(&bat_mutex);
- }
- if (!g_bat.down)
- pr_err("%s: failed to terminate battery thread\n", __func__);
- #endif
- /* turn down interrupt thread and wakeup ability */
- if (g_bat.init_done)
- irq_set_irq_wake(g_bat.irq, false);
- free_irq(g_bat.irq, pdev);
- mutex_unlock(&bat_mutex);
- }
- static int battery_suspend(struct platform_device *dev, pm_message_t state)
- {
- disable_irq(g_bat.irq);
- mutex_lock(&bat_mutex);
- battery_suspended = true;
- mutex_unlock(&bat_mutex);
- return 0;
- }
- static int battery_resume(struct platform_device *dev)
- {
- battery_suspended = false;
- g_refresh_ui_soc = true;
- if (bat_charger_is_pcm_timer_trigger())
- wake_up_bat_update_meter();
- enable_irq(g_bat.irq);
- return 0;
- }
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // Battery Notify API */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- #if !defined(CONFIG_POWER_EXT)
- static ssize_t show_BatteryNotify(struct device *dev, struct device_attribute *attr, char *buf)
- {
- battery_log(BAT_LOG_CRTI, "[Battery] show_BatteryNotify : %x\n", g_BatteryNotifyCode);
- return sprintf(buf, "%u\n", g_BatteryNotifyCode);
- }
- static ssize_t store_BatteryNotify(struct device *dev, struct device_attribute *attr,
- const char *buf, size_t size)
- {
- unsigned int reg_BatteryNotifyCode, ret;
- if (buf != NULL && size != 0) {
- ret = kstrtouint(buf, 0, ®_BatteryNotifyCode);
- if (ret) {
- pr_err("wrong format!\n");
- return size;
- }
- g_BatteryNotifyCode = reg_BatteryNotifyCode;
- battery_log(BAT_LOG_CRTI, "[Battery] store code : %x\n", g_BatteryNotifyCode);
- }
- return size;
- }
- static DEVICE_ATTR(BatteryNotify, 0664, show_BatteryNotify, store_BatteryNotify);
- static ssize_t show_BN_TestMode(struct device *dev, struct device_attribute *attr, char *buf)
- {
- battery_log(BAT_LOG_CRTI, "[Battery] show_BN_TestMode : %x\n", g_BN_TestMode);
- return sprintf(buf, "%u\n", g_BN_TestMode);
- }
- static ssize_t store_BN_TestMode(struct device *dev, struct device_attribute *attr, const char *buf,
- size_t size)
- {
- unsigned int reg_BN_TestMode, ret;
- if (buf != NULL && size != 0) {
- ret = kstrtouint(buf, 0, ®_BN_TestMode);
- if (ret) {
- pr_err("wrong format!\n");
- return size;
- }
- g_BN_TestMode = reg_BN_TestMode;
- battery_log(BAT_LOG_CRTI, "[Battery] store g_BN_TestMode : %x\n", g_BN_TestMode);
- }
- return size;
- }
- static DEVICE_ATTR(BN_TestMode, 0664, show_BN_TestMode, store_BN_TestMode);
- #endif
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- /* // platform_driver API */
- /* ///////////////////////////////////////////////////////////////////////////////////////// */
- #if 0
- static int battery_cmd_read(char *buf, char **start, off_t off, int count, int *eof, void *data)
- {
- int len = 0;
- char *p = buf;
- p += sprintf(p,
- "g_battery_thermal_throttling_flag=%d,\nbattery_cmd_thermal_test_mode=%d,\nbattery_cmd_thermal_test_mode_value=%d\n",
- g_battery_thermal_throttling_flag, battery_cmd_thermal_test_mode,
- battery_cmd_thermal_test_mode_value);
- *start = buf + off;
- len = p - buf;
- if (len > off)
- len -= off;
- else
- len = 0;
- return len < count ? len : count;
- }
- #endif
- static ssize_t battery_cmd_write(struct file *file, const char *buffer, size_t count, loff_t *data)
- {
- int len = 0, bat_tt_enable = 0, bat_thr_test_mode = 0, bat_thr_test_value = 0;
- char desc[32];
- len = (count < (sizeof(desc) - 1)) ? count : (sizeof(desc) - 1);
- if (copy_from_user(desc, buffer, len))
- return 0;
- desc[len] = '\0';
- if (sscanf(desc, "%d %d %d", &bat_tt_enable, &bat_thr_test_mode, &bat_thr_test_value) == 3) {
- g_battery_thermal_throttling_flag = bat_tt_enable;
- battery_cmd_thermal_test_mode = bat_thr_test_mode;
- battery_cmd_thermal_test_mode_value = bat_thr_test_value;
- battery_log(BAT_LOG_CRTI,
- "bat_tt_enable=%d, bat_thr_test_mode=%d, bat_thr_test_value=%d\n",
- g_battery_thermal_throttling_flag,
- battery_cmd_thermal_test_mode, battery_cmd_thermal_test_mode_value);
- return count;
- }
- battery_log(BAT_LOG_CRTI,
- " bad argument, echo [bat_tt_enable] [bat_thr_test_mode] [bat_thr_test_value] > battery_cmd\n");
- return -EINVAL;
- }
- static int proc_utilization_show(struct seq_file *m, void *v)
- {
- seq_printf(m,
- "=> g_battery_thermal_throttling_flag=%d,\nbattery_cmd_thermal_test_mode=%d,\nbattery_cmd_thermal_test_mode_value=%d\n",
- g_battery_thermal_throttling_flag, battery_cmd_thermal_test_mode,
- battery_cmd_thermal_test_mode_value);
- return 0;
- }
- static int proc_utilization_open(struct inode *inode, struct file *file)
- {
- return single_open(file, proc_utilization_show, NULL);
- }
- static const struct file_operations battery_cmd_proc_fops = {
- .open = proc_utilization_open,
- .read = seq_read,
- .write = battery_cmd_write,
- };
- static int mt_batteryNotify_probe(struct platform_device *pdev)
- {
- #if defined(CONFIG_POWER_EXT)
- #else
- struct device *dev = &pdev->dev;
- int ret_device_file = 0;
- /* struct proc_dir_entry *entry = NULL; */
- struct proc_dir_entry *battery_dir = NULL;
- battery_log(BAT_LOG_CRTI, "******** mt_batteryNotify_probe!! ********\n");
- ret_device_file = device_create_file(dev, &dev_attr_BatteryNotify);
- ret_device_file = device_create_file(dev, &dev_attr_BN_TestMode);
- battery_dir = proc_mkdir("mtk_battery_cmd", NULL);
- if (!battery_dir) {
- pr_err("[%s]: mkdir /proc/mtk_battery_cmd failed\n", __func__);
- } else {
- #if 1
- proc_create("battery_cmd", S_IRUGO | S_IWUSR, battery_dir, &battery_cmd_proc_fops);
- battery_log(BAT_LOG_CRTI, "proc_create battery_cmd_proc_fops\n");
- #else
- entry = create_proc_entry("battery_cmd", S_IRUGO | S_IWUSR, battery_dir);
- if (entry) {
- entry->read_proc = battery_cmd_read;
- entry->write_proc = battery_cmd_write;
- }
- #endif
- }
- battery_log(BAT_LOG_CRTI, "******** mtk_battery_cmd!! ********\n");
- #endif
- return 0;
- }
- #if 0 /* move to board-common-battery.c */
- struct platform_device battery_device = {
- .name = "battery",
- .id = -1,
- };
- #endif
- static struct platform_driver battery_driver = {
- .probe = battery_probe,
- .remove = battery_remove,
- .shutdown = battery_shutdown,
- /* #ifdef CONFIG_PM */
- .suspend = battery_suspend,
- .resume = battery_resume,
- /* #endif */
- .driver = {
- .name = "battery",
- #ifdef CONFIG_OF
- .of_match_table = of_match_ptr(mt_battery_common_id),
- #endif
- },
- };
- struct platform_device MT_batteryNotify_device = {
- .name = "mt-battery",
- .id = -1,
- };
- static struct platform_driver mt_batteryNotify_driver = {
- .probe = mt_batteryNotify_probe,
- .driver = {
- .name = "mt-battery",
- },
- };
- static int __init battery_init(void)
- {
- int ret;
- #if 0 /* move to board-common-battery.c */
- ret = platform_device_register(&battery_device);
- if (ret) {
- battery_log(BAT_LOG_CRTI,
- "****[battery_driver] Unable to device register(%d)\n", ret);
- return ret;
- }
- #endif
- ret = platform_driver_register(&battery_driver);
- if (ret) {
- battery_log(BAT_LOG_CRTI,
- "****[battery_driver] Unable to register driver (%d)\n", ret);
- return ret;
- }
- /* battery notofy UI */
- ret = platform_device_register(&MT_batteryNotify_device);
- if (ret) {
- battery_log(BAT_LOG_CRTI,
- "****[mt_batteryNotify] Unable to device register(%d)\n", ret);
- return ret;
- }
- ret = platform_driver_register(&mt_batteryNotify_driver);
- if (ret) {
- battery_log(BAT_LOG_CRTI,
- "****[mt_batteryNotify] Unable to register driver (%d)\n", ret);
- return ret;
- }
- battery_log(BAT_LOG_CRTI, "****[battery_driver] Initialization : DONE !!\n");
- return 0;
- }
- static void __exit battery_exit(void)
- {
- }
- /* move to late_initcall to ensure battery_meter probe first */
- /* module_init(battery_init); */
- late_initcall(battery_init);
- module_exit(battery_exit);
- MODULE_AUTHOR("Oscar Liu");
- MODULE_DESCRIPTION("Battery Device Driver");
- MODULE_LICENSE("GPL");
|