sec_battery.h 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  1. /*
  2. * sec_battery.h
  3. * Samsung Mobile Battery Header
  4. *
  5. *
  6. * Copyright (C) 2012 Samsung Electronics, Inc.
  7. *
  8. *
  9. * This software is licensed under the terms of the GNU General Public
  10. * License version 2, as published by the Free Software Foundation, and
  11. * may be copied, distributed, and modified under those terms.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. */
  19. #ifndef __SEC_BATTERY_H
  20. #define __SEC_BATTERY_H __FILE__
  21. #include "sec_charging_common.h"
  22. #include <linux/of_gpio.h>
  23. #include <linux/alarmtimer.h>
  24. #include <linux/pm_wakeup.h>
  25. #include <linux/workqueue.h>
  26. #include <linux/proc_fs.h>
  27. #include <linux/jiffies.h>
  28. #include <linux/i2c.h>
  29. #if IS_ENABLED(CONFIG_PDIC_NOTIFIER)
  30. #include <linux/usb/typec/common/pdic_notifier.h>
  31. #endif
  32. #if IS_ENABLED(CONFIG_USB_TYPEC_MANAGER_NOTIFIER)
  33. #include <linux/usb/typec/manager/usb_typec_manager_notifier.h>
  34. #else
  35. #if IS_ENABLED(CONFIG_MUIC_NOTIFIER)
  36. #include <linux/muic/common/muic.h>
  37. #include <linux/muic/common/muic_notifier.h>
  38. #endif
  39. #endif
  40. #include <linux/battery/sec_pd.h>
  41. #include "sec_cisd.h"
  42. #if IS_ENABLED(CONFIG_DIRECT_CHARGING)
  43. #include "sec_direct_charger.h"
  44. #endif
  45. #if defined(CONFIG_WIRELESS_AUTH)
  46. #include "sec_battery_misc.h"
  47. #endif
  48. #include "sec_adc.h"
  49. #include "sb_checklist_app.h"
  50. #include "sb_full_soc.h"
  51. extern const char *sb_get_ct_str(int cable_type);
  52. extern const char *sb_get_cm_str(int chg_mode);
  53. extern const char *sb_get_bst_str(int st);
  54. extern const char *sb_get_hl_str(int health);
  55. extern const char *sb_get_tz_str(int tz);
  56. extern const char *sb_charge_mode_str(int charge_mode);
  57. #ifndef EXPORT_SYMBOL_KUNIT
  58. #define EXPORT_SYMBOL_KUNIT(sym) /* nothing */
  59. #endif
  60. /* current event */
  61. #define SEC_BAT_CURRENT_EVENT_NONE 0x000000
  62. #define SEC_BAT_CURRENT_EVENT_AFC 0x000001
  63. #define SEC_BAT_CURRENT_EVENT_CHARGE_DISABLE 0x000002
  64. #define SEC_BAT_CURRENT_EVENT_SKIP_HEATING_CONTROL 0x000004
  65. #define SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING_COOL1 0x000008
  66. #define SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING 0x000020
  67. #define SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING_COOL2 0x000080
  68. #define SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING_COOL3 0x000010
  69. #define SEC_BAT_CURRENT_EVENT_SWELLING_MODE (SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING_COOL1 | SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING_COOL2 | SEC_BAT_CURRENT_EVENT_HIGH_TEMP_SWELLING | SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING_COOL3)
  70. #define SEC_BAT_CURRENT_EVENT_LOW_TEMP_MODE (SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING_COOL1 | SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING_COOL2 | SEC_BAT_CURRENT_EVENT_LOW_TEMP_SWELLING_COOL3)
  71. #define SEC_BAT_CURRENT_EVENT_CHG_LIMIT 0x000200
  72. #define SEC_BAT_CURRENT_EVENT_CALL 0x000400
  73. #define SEC_BAT_CURRENT_EVENT_SLATE 0x000800
  74. #define SEC_BAT_CURRENT_EVENT_VBAT_OVP 0x001000
  75. #define SEC_BAT_CURRENT_EVENT_VSYS_OVP 0x002000
  76. #define SEC_BAT_CURRENT_EVENT_WPC_VOUT_LOCK 0x004000
  77. #define SEC_BAT_CURRENT_EVENT_AICL 0x008000
  78. #define SEC_BAT_CURRENT_EVENT_HV_DISABLE 0x010000
  79. #define SEC_BAT_CURRENT_EVENT_SELECT_PDO 0x020000
  80. #define SEC_BAT_CURRENT_EVENT_FG_RESET 0x040000
  81. #define SEC_BAT_CURRENT_EVENT_WDT_EXPIRED 0x080000
  82. #define SEC_BAT_CURRENT_EVENT_NOPD_HV_DISABLE 0x100000
  83. #if defined(CONFIG_ISDB_CHARGING_CONTROL)
  84. #define SEC_BAT_CURRENT_EVENT_ISDB 0x200000
  85. #else
  86. #define SEC_BAT_CURRENT_EVENT_ISDB 0x000000
  87. #endif
  88. #define SEC_BAT_CURRENT_EVENT_DC_ERR 0x400000
  89. #define SEC_BAT_CURRENT_EVENT_SIOP_LIMIT 0x800000
  90. #define SEC_BAT_CURRENT_EVENT_TEMP_CTRL_TEST 0x1000000
  91. #define SEC_BAT_CURRENT_EVENT_25W_OCP 0x2000000
  92. #define SEC_BAT_CURRENT_EVENT_AFC_DISABLE 0x4000000
  93. #define SEC_BAT_CURRENT_EVENT_SEND_UVDM 0x8000000
  94. #define SEC_BAT_CURRENT_EVENT_USB_SUSPENDED 0x10000000
  95. #define SEC_BAT_CURRENT_EVENT_USB_SUPER 0x20000000
  96. #define SEC_BAT_CURRENT_EVENT_USB_100MA 0x40000000
  97. #define SEC_BAT_CURRENT_EVENT_USB_STATE (SEC_BAT_CURRENT_EVENT_USB_SUSPENDED |\
  98. SEC_BAT_CURRENT_EVENT_USB_SUPER |\
  99. SEC_BAT_CURRENT_EVENT_USB_100MA)
  100. #define SEC_BAT_CURRENT_EVENT_WPC_EN 0x80000000
  101. /* misc_event */
  102. #define BATT_MISC_EVENT_UNDEFINED_RANGE_TYPE 0x00000001
  103. #define BATT_MISC_EVENT_WIRELESS_BACKPACK_TYPE 0x00000002
  104. #define BATT_MISC_EVENT_TIMEOUT_OPEN_TYPE 0x00000004
  105. #define BATT_MISC_EVENT_BATT_RESET_SOC 0x00000008
  106. #define BATT_MISC_EVENT_WATER_HICCUP_TYPE 0x00000020
  107. #define BATT_MISC_EVENT_WIRELESS_DET_LEVEL 0x00000040
  108. #define BATT_MISC_EVENT_WIRELESS_FOD 0x00000100
  109. #define BATT_MISC_EVENT_WIRELESS_AUTH_START 0x00000200
  110. #define BATT_MISC_EVENT_WIRELESS_AUTH_RECVED 0x00000400
  111. #define BATT_MISC_EVENT_WIRELESS_AUTH_FAIL 0x00000800
  112. #define BATT_MISC_EVENT_WIRELESS_AUTH_PASS 0x00001000
  113. #define BATT_MISC_EVENT_TEMP_HICCUP_TYPE 0x00002000
  114. #define BATT_MISC_EVENT_DIRECT_POWER_MODE 0x00004000
  115. #define BATT_MISC_EVENT_BATTERY_HEALTH 0x000F0000
  116. #define BATT_MISC_EVENT_HEALTH_OVERHEATLIMIT 0x00100000
  117. //#define BATT_MISC_EVENT_ABNORMAL_PAD 0x00200000
  118. #define BATT_MISC_EVENT_WIRELESS_MISALIGN 0x00400000
  119. #define BATT_MISC_EVENT_FULL_CAPACITY 0x01000000
  120. #define BATT_MISC_EVENT_PASS_THROUGH 0x02000000
  121. #define BATT_MISC_EVENT_MAIN_POWERPATH 0x04000000
  122. #define BATT_MISC_EVENT_SUB_POWERPATH 0x08000000
  123. #define BATT_MISC_EVENT_HV_BY_AICL 0x10000000
  124. #define BATT_MISC_EVENT_WC_JIG_PAD 0x20000000
  125. #define BATTERY_HEALTH_SHIFT 16
  126. enum misc_battery_health {
  127. BATTERY_HEALTH_UNKNOWN = 0,
  128. BATTERY_HEALTH_GOOD,
  129. BATTERY_HEALTH_NORMAL,
  130. BATTERY_HEALTH_AGED,
  131. BATTERY_HEALTH_MAX = BATTERY_HEALTH_AGED,
  132. /* For event */
  133. BATTERY_HEALTH_BAD = 0xF,
  134. };
  135. #define BATT_MISC_EVENT_MUIC_ABNORMAL (BATT_MISC_EVENT_UNDEFINED_RANGE_TYPE |\
  136. BATT_MISC_EVENT_WATER_HICCUP_TYPE |\
  137. BATT_MISC_EVENT_TEMP_HICCUP_TYPE)
  138. #define DEFAULT_HEALTH_CHECK_COUNT 5
  139. #define SIOP_INPUT_LIMIT_CURRENT 1200
  140. #define SIOP_CHARGING_LIMIT_CURRENT 1800
  141. #define SIOP_WIRELESS_INPUT_LIMIT_CURRENT 600
  142. #define SIOP_HV_WIRELESS_INPUT_LIMIT_CURRENT 700
  143. #define SIOP_STORE_HV_WIRELESS_CHARGING_LIMIT_CURRENT 450
  144. #define SIOP_HV_INPUT_LIMIT_CURRENT 700
  145. #define SIOP_HV_CHARGING_LIMIT_CURRENT 1800
  146. #define SIOP_HV_12V_INPUT_LIMIT_CURRENT 535
  147. #define SIOP_HV_12V_CHARGING_LIMIT_CURRENT 1000
  148. #define SIOP_APDO_INPUT_LIMIT_CURRENT 1000
  149. #define SIOP_APDO_CHARGING_LIMIT_CURRENT 2000
  150. #define WIRELESS_OTG_INPUT_CURRENT 900
  151. enum {
  152. SEC_INPUT_VOLTAGE_0V = 0,
  153. SEC_INPUT_VOLTAGE_NONE = 1000,
  154. SEC_INPUT_VOLTAGE_APDO = 1234,
  155. SEC_INPUT_VOLTAGE_5V = 5000,
  156. SEC_INPUT_VOLTAGE_5_5V = 5500,
  157. SEC_INPUT_VOLTAGE_9V = 9000,
  158. SEC_INPUT_VOLTAGE_10V = 10000,
  159. SEC_INPUT_VOLTAGE_12V = 12000,
  160. SEC_INPUT_VOLTAGE_12_5V = 12500,
  161. };
  162. #define HV_CHARGER_STATUS_STANDARD1 12000 /* mW */
  163. #define HV_CHARGER_STATUS_STANDARD2 20000 /* mW */
  164. #define HV_CHARGER_STATUS_STANDARD3 24500 /* mW */
  165. #define HV_CHARGER_STATUS_STANDARD4 40000 /* mW */
  166. #define WFC10_WIRELESS_POWER 7500000 /* mW */
  167. #define WFC20_WIRELESS_POWER 12000000 /* mW */
  168. #define WFC21_WIRELESS_POWER 15000000 /* mW */
  169. #define mW_by_mVmA(v, a) ((v) * (a) / 1000)
  170. #define mV_by_mWmA(w, a) ((a) ? (((w) * 1000) / (a)) : (0))
  171. #define mA_by_mWmV(w, v) ((v) ? (((w) * 1000) / (v)) : (0))
  172. enum battery_misc_test {
  173. MISC_TEST_RESET = 0,
  174. MISC_TEST_DISPLAY,
  175. MISC_TEST_EPT_UNKNOWN,
  176. MISC_TEST_MAX,
  177. };
  178. enum {
  179. NORMAL_TA,
  180. AFC_9V_OR_15W,
  181. AFC_12V_OR_20W,
  182. SFC_25W,
  183. SFC_45W,
  184. };
  185. struct sec_bat_pdic_list {
  186. unsigned int max_pd_count;
  187. bool now_isApdo;
  188. unsigned int num_fpdo;
  189. unsigned int num_apdo;
  190. };
  191. enum {
  192. USB_CONN_NORMAL = 0x0,
  193. USB_CONN_SLOPE_OVER = 0x1,
  194. USB_CONN_GAP_OVER1 = 0x2,
  195. USB_CONN_GAP_OVER2 = 0x4,
  196. USB_CONN_OVERHEATLIMIT = 0x8,
  197. };
  198. #define MAX_USB_CONN_CHECK_CNT 10
  199. typedef struct sec_charging_current {
  200. unsigned int input_current_limit;
  201. unsigned int fast_charging_current;
  202. #if IS_ENABLED(CONFIG_DUAL_BATTERY)
  203. unsigned int main_limiter_current;
  204. unsigned int sub_limiter_current;
  205. #endif
  206. } sec_charging_current_t;
  207. /**
  208. * struct sec_bat_adc_table_data - adc to temperature table for sec battery
  209. * driver
  210. * @adc: adc value
  211. * @temperature: temperature(C) * 10
  212. */
  213. typedef struct sec_bat_adc_table_data {
  214. int adc;
  215. int data;
  216. } sec_bat_adc_table_data_t;
  217. typedef struct sec_bat_adc_region {
  218. int min;
  219. int max;
  220. } sec_bat_adc_region_t;
  221. /* nv, hv, fpdo, apdo, wpc, wpc_hv */
  222. enum sec_siop_curr_type {
  223. SIOP_CURR_TYPE_NV = 0,
  224. SIOP_CURR_TYPE_HV,
  225. SIOP_CURR_TYPE_FPDO,
  226. SIOP_CURR_TYPE_APDO,
  227. SIOP_CURR_TYPE_WPC_NV,
  228. SIOP_CURR_TYPE_WPC_HV,
  229. SIOP_CURR_TYPE_MAX,
  230. };
  231. struct sec_siop_table {
  232. int level;
  233. int icl[SIOP_CURR_TYPE_MAX];
  234. int fcc[SIOP_CURR_TYPE_MAX];
  235. };
  236. #define SIOP_SCENARIO_NUM_MAX 10
  237. struct sec_bat_thm_info {
  238. int source;
  239. sec_bat_adc_table_data_t *adc_table;
  240. unsigned int adc_table_size;
  241. int offset;
  242. int check_type;
  243. unsigned int check_count;
  244. int test;
  245. int adc;
  246. int channel;
  247. };
  248. enum sec_battery_thm_info {
  249. THM_INFO_NONE = 0,
  250. THM_INFO_BAT,
  251. THM_INFO_USB,
  252. THM_INFO_CHG,
  253. THM_INFO_WPC,
  254. THM_INFO_SUB_BAT,
  255. THM_INFO_BLK,
  256. THM_INFO_DCHG,
  257. };
  258. /* LRP structure */
  259. #define LRP_PROPS 12
  260. #define FOREACH_LRP_TYPE(GEN_LRP_TYPE) \
  261. GEN_LRP_TYPE(LRP_NORMAL) \
  262. GEN_LRP_TYPE(LRP_25W) \
  263. GEN_LRP_TYPE(LRP_45W) \
  264. GEN_LRP_TYPE(LRP_MAX)
  265. #define GENERATE_LRP_ENUM(ENUM) ENUM,
  266. #define GENERATE_LRP_STRING(STRING) #STRING,
  267. enum LRP_TYPE_ENUM {
  268. FOREACH_LRP_TYPE(GENERATE_LRP_ENUM)
  269. };
  270. static const char * const LRP_TYPE_STRING[] = {
  271. FOREACH_LRP_TYPE(GENERATE_LRP_STRING)
  272. };
  273. enum {
  274. LRP_NONE = 0,
  275. LRP_STEP1,
  276. LRP_STEP2,
  277. };
  278. enum {
  279. ST1 = 0,
  280. ST2,
  281. };
  282. enum {
  283. LCD_ON = 0,
  284. LCD_OFF,
  285. };
  286. struct lrp_temp_t {
  287. int trig[2][2];
  288. int recov[2][2];
  289. };
  290. struct lrp_current_t {
  291. int st_icl[2];
  292. int st_fcc[2];
  293. };
  294. typedef struct sec_battery_platform_data {
  295. /* NO NEED TO BE CHANGED */
  296. /* callback functions */
  297. void (*initial_check)(void);
  298. void (*monitor_additional_check)(void);
  299. bool (*bat_gpio_init)(void);
  300. bool (*fg_gpio_init)(void);
  301. bool (*is_lpm)(void);
  302. bool (*check_jig_status)(void);
  303. bool (*is_interrupt_cable_check_possible)(int);
  304. int (*check_cable_callback)(void);
  305. int (*get_cable_from_extended_cable_type)(int);
  306. bool (*cable_switch_check)(void);
  307. bool (*cable_switch_normal)(void);
  308. bool (*check_cable_result_callback)(int);
  309. bool (*check_battery_callback)(void);
  310. bool (*check_battery_result_callback)(void);
  311. int (*ovp_uvlo_callback)(void);
  312. bool (*ovp_uvlo_result_callback)(int);
  313. bool (*fuelalert_process)(bool);
  314. bool (*get_temperature_callback)(
  315. enum power_supply_property,
  316. union power_supply_propval*);
  317. /* ADC region by power supply type
  318. * ADC region should be exclusive
  319. */
  320. sec_bat_adc_region_t *cable_adc_value;
  321. /* charging current for type (0: not use) */
  322. sec_charging_current_t charging_current[SEC_BATTERY_CABLE_MAX];
  323. unsigned int *polling_time;
  324. char *chip_vendor;
  325. /* NO NEED TO BE CHANGED */
  326. unsigned int pre_afc_input_current;
  327. unsigned int pre_wc_afc_input_current;
  328. unsigned int select_pd_input_current;
  329. unsigned int store_mode_max_input_power;
  330. char *pmic_name;
  331. /* battery */
  332. char *vendor;
  333. int technology;
  334. void *battery_data;
  335. int bat_gpio_ta_nconnected;
  336. /* 1 : active high, 0 : active low */
  337. int bat_polarity_ta_nconnected;
  338. sec_battery_cable_check_t cable_check_type;
  339. sec_battery_cable_source_t cable_source_type;
  340. unsigned int swelling_high_rechg_voltage;
  341. unsigned int swelling_low_rechg_voltage;
  342. unsigned int swelling_low_cool3_rechg_voltage;
  343. bool chgen_over_swell_rechg_vol;
  344. #if IS_ENABLED(CONFIG_STEP_CHARGING)
  345. /* step charging */
  346. unsigned int **step_chg_cond;
  347. unsigned int **wpc_step_chg_cond;
  348. unsigned int **step_chg_cond_soc;
  349. #if IS_ENABLED(CONFIG_DUAL_BATTERY)
  350. unsigned int **step_chg_cond_sub;
  351. #endif
  352. unsigned int *step_chg_cond_curr;
  353. unsigned int **step_chg_curr;
  354. unsigned int **step_chg_vfloat;
  355. unsigned int *wpc_step_chg_cond_curr;
  356. unsigned int **wpc_step_chg_curr;
  357. unsigned int **wpc_step_chg_vfloat;
  358. #if IS_ENABLED(CONFIG_DIRECT_CHARGING)
  359. #if IS_ENABLED(CONFIG_DUAL_BATTERY)
  360. unsigned int **dc_step_chg_cond_vol_sub;
  361. unsigned int dc_step_cond_v_margin_main;
  362. unsigned int dc_step_cond_v_margin_sub;
  363. unsigned int sc_vbat_thresh_main; /* main vbat threshold which dc to sc */
  364. unsigned int sc_vbat_thresh_sub; /* sub vbat threshold which dc to sc */
  365. #endif
  366. unsigned int dc_step_chg_cond_v_margin;
  367. unsigned int **dc_step_chg_cond_vol;
  368. unsigned int **dc_step_chg_cond_soc;
  369. unsigned int *dc_step_chg_cond_iin;
  370. unsigned int *dc_step_chg_vol_offset;
  371. int dc_step_chg_iin_check_cnt;
  372. unsigned int **dc_step_chg_val_iout;
  373. unsigned int **dc_step_chg_val_vfloat;
  374. #endif
  375. #endif
  376. /* Monitor setting */
  377. int polling_type;
  378. /* for initial check */
  379. unsigned int monitor_initial_count;
  380. /* Battery check */
  381. sec_battery_check_t battery_check_type;
  382. /* how many times do we need to check battery */
  383. unsigned int check_count;
  384. /* ADC */
  385. /* battery check ADC maximum value */
  386. unsigned int check_adc_max;
  387. /* battery check ADC minimum value */
  388. unsigned int check_adc_min;
  389. /* OVP/UVLO check */
  390. int ovp_uvlo_check_type;
  391. struct sec_bat_thm_info bat_thm_info;
  392. struct sec_bat_thm_info usb_thm_info;
  393. struct sec_bat_thm_info chg_thm_info;
  394. struct sec_bat_thm_info wpc_thm_info;
  395. struct sec_bat_thm_info sub_bat_thm_info;
  396. struct sec_bat_thm_info blk_thm_info;
  397. struct sec_bat_thm_info dchg_thm_info;
  398. bool dctp_by_cgtp;
  399. bool dctp_bootmode_en;
  400. bool lrpts_by_batts;
  401. int usb_temp_check_type_backup; /* sec_bat_set_temp_control_test() */
  402. int lrp_temp_check_type;
  403. unsigned int temp_check_count;
  404. sec_bat_adc_table_data_t *inbat_adc_table;
  405. unsigned int inbat_adc_table_size;
  406. unsigned int inbat_voltage;
  407. unsigned int inbat_ocv_type;
  408. /*
  409. * limit can be ADC value or Temperature
  410. * depending on temp_check_type
  411. * temperature should be temp x 10 (0.1 degree)
  412. */
  413. int wireless_cold_cool3_thresh;
  414. int wireless_cool3_cool2_thresh;
  415. int wireless_cool2_cool1_thresh;
  416. int wireless_cool1_normal_thresh;
  417. int wireless_normal_warm_thresh;
  418. int wireless_warm_overheat_thresh;
  419. int wire_cold_cool3_thresh;
  420. int wire_cool3_cool2_thresh;
  421. int wire_cool2_cool1_thresh;
  422. int wire_cool1_normal_thresh;
  423. int wire_normal_warm_thresh;
  424. int wire_warm_overheat_thresh;
  425. int wire_warm_current;
  426. int wire_cool1_current;
  427. int wire_cool2_current;
  428. int wire_cool3_current;
  429. int wireless_warm_current;
  430. int wireless_cool1_current;
  431. int wireless_cool2_current;
  432. int wireless_cool3_current;
  433. int high_temp_float;
  434. int low_temp_float;
  435. int low_temp_cool3_float;
  436. #if IS_ENABLED(CONFIG_DUAL_BATTERY)
  437. unsigned int limiter_main_warm_current;
  438. unsigned int limiter_sub_warm_current;
  439. unsigned int limiter_main_cool1_current;
  440. unsigned int limiter_sub_cool1_current;
  441. unsigned int limiter_main_cool2_current;
  442. unsigned int limiter_sub_cool2_current;
  443. unsigned int limiter_main_cool3_current;
  444. unsigned int limiter_sub_cool3_current;
  445. unsigned int limiter_aging_float_offset;
  446. #endif
  447. int buck_recovery_margin;
  448. int tx_high_threshold;
  449. int tx_high_recovery;
  450. int tx_low_threshold;
  451. int tx_low_recovery;
  452. int chg_12v_high_temp;
  453. int chg_high_temp;
  454. int chg_high_temp_recovery;
  455. int dchg_high_temp[4];
  456. int dchg_high_temp_recovery[4];
  457. int dchg_high_batt_temp[4];
  458. int dchg_high_batt_temp_recovery[4];
  459. struct lrp_temp_t lrp_temp[LRP_MAX];
  460. struct lrp_current_t lrp_curr[LRP_MAX];
  461. unsigned int chg_charging_limit_current;
  462. unsigned int chg_input_limit_current;
  463. unsigned int dchg_charging_limit_current;
  464. unsigned int dchg_input_limit_current;
  465. unsigned int sub_temp_control_source;
  466. unsigned int wpc_temp_control_source;
  467. unsigned int wpc_temp_lcd_on_control_source;
  468. int wpc_high_temp;
  469. int wpc_high_temp_recovery;
  470. int wpc_high_temp_12w;
  471. int wpc_high_temp_recovery_12w;
  472. int wpc_high_temp_15w;
  473. int wpc_high_temp_recovery_15w;
  474. unsigned int wpc_input_limit_current;
  475. unsigned int wpc_charging_limit_current;
  476. bool enable_check_wpc_temp_v2;
  477. int wpc_temp_v2_cond;
  478. int wpc_temp_v2_cond_12w;
  479. int wpc_temp_v2_cond_15w;
  480. int wpc_lrp_high_temp;
  481. int wpc_lrp_high_temp_recovery;
  482. int wpc_lrp_high_temp_12w;
  483. int wpc_lrp_high_temp_recovery_12w;
  484. int wpc_lrp_high_temp_15w;
  485. int wpc_lrp_high_temp_recovery_15w;
  486. int wpc_lrp_temp_v2_cond;
  487. int wpc_lrp_temp_v2_cond_12w;
  488. int wpc_lrp_temp_v2_cond_15w;
  489. unsigned int wpc_step_limit_size;
  490. unsigned int *wpc_step_limit_temp;
  491. unsigned int *wpc_step_limit_fcc;
  492. unsigned int *wpc_step_limit_fcc_12w;
  493. unsigned int *wpc_step_limit_fcc_15w;
  494. int wpc_lcd_on_high_temp;
  495. int wpc_lcd_on_high_temp_rec;
  496. int wpc_lcd_on_high_temp_12w;
  497. int wpc_lcd_on_high_temp_rec_12w;
  498. int wpc_lcd_on_high_temp_15w;
  499. int wpc_lcd_on_high_temp_rec_15w;
  500. unsigned int wpc_lcd_on_input_limit_current;
  501. unsigned int wpc_flicker_wa_input_limit_current;
  502. unsigned int sleep_mode_limit_current;
  503. unsigned int wc_full_input_limit_current;
  504. unsigned int max_charging_current;
  505. unsigned int max_charging_charge_power;
  506. unsigned int apdo_max_volt;
  507. int mix_high_temp;
  508. int mix_high_chg_temp;
  509. int mix_high_temp_recovery;
  510. bool enable_mix_v2;
  511. int mix_v2_lrp_recov;
  512. int mix_v2_lrp_cond;
  513. int mix_v2_bat_cond;
  514. int mix_v2_chg_cond;
  515. int mix_v2_dchg_cond;
  516. bool wpc_high_check_using_lrp;
  517. unsigned int icl_by_tx_gear; /* check limited charging current during wireless power sharing with cable charging */
  518. unsigned int fcc_by_tx;
  519. unsigned int fcc_by_tx_gear;
  520. unsigned int wpc_input_limit_by_tx_check; /* check limited wpc input current with tx device */
  521. unsigned int wpc_input_limit_current_by_tx;
  522. /* If these is NOT full check type or NONE full check type,
  523. * it is skipped
  524. */
  525. /* 1st full check */
  526. int full_check_type;
  527. /* 2nd full check */
  528. int full_check_type_2nd;
  529. unsigned int full_check_count;
  530. int chg_gpio_full_check;
  531. /* 1 : active high, 0 : active low */
  532. int chg_polarity_full_check;
  533. sec_battery_full_condition_t full_condition_type;
  534. unsigned int full_condition_soc;
  535. unsigned int full_condition_vcell;
  536. unsigned int full_condition_avgvcell;
  537. unsigned int full_condition_ocv;
  538. unsigned int recharge_check_count;
  539. sec_battery_recharge_condition_t recharge_condition_type;
  540. unsigned int recharge_condition_soc;
  541. unsigned int recharge_condition_vcell;
  542. unsigned long charging_reset_time;
  543. /* fuel gauge */
  544. char *fuelgauge_name;
  545. unsigned int store_mode_charging_max;
  546. unsigned int store_mode_charging_min;
  547. unsigned int store_mode_buckoff;
  548. /* charger */
  549. char *charger_name;
  550. char *otg_name;
  551. char *fgsrc_switch_name;
  552. bool support_fgsrc_change;
  553. bool dynamic_cv_factor;
  554. bool slowcharging_usb_bootcomplete;
  555. /* wireless charger */
  556. char *wireless_charger_name;
  557. int wireless_cc_cv;
  558. bool p2p_cv_headroom;
  559. /* float voltage (mV) */
  560. unsigned int chg_float_voltage;
  561. unsigned int chg_float_voltage_conv;
  562. #if IS_ENABLED(CONFIG_DUAL_BATTERY)
  563. /* current limiter */
  564. char *dual_battery_name;
  565. char *main_limiter_name;
  566. char *sub_limiter_name;
  567. int main_bat_enb_gpio;
  568. int main_bat_enb2_gpio;
  569. int sub_bat_enb_gpio;
  570. #endif
  571. #if IS_ENABLED(CONFIG_DUAL_FUELGAUGE)
  572. char *dual_fuelgauge_name;
  573. char *main_fuelgauge_name;
  574. char *sub_fuelgauge_name;
  575. unsigned int main_design_capacity;
  576. unsigned int sub_design_capacity;
  577. #endif
  578. int num_age_step;
  579. int age_step;
  580. sec_age_data_t* age_data;
  581. battery_health_condition* health_condition;
  582. int siop_icl;
  583. int siop_fcc;
  584. int siop_hv_icl;
  585. int siop_hv_icl_2nd;
  586. int siop_hv_fcc;
  587. int siop_hv_12v_icl;
  588. int siop_hv_12v_fcc;
  589. int siop_apdo_icl;
  590. int siop_apdo_fcc;
  591. int siop_wpc_icl;
  592. int *siop_wpc_fcc;
  593. int siop_hv_wpc_icl;
  594. int rechg_hv_wpc_icl;
  595. int *siop_hv_wpc_fcc;
  596. int wireless_otg_input_current;
  597. int wc_hero_stand_cc_cv;
  598. int wc_hero_stand_cv_current;
  599. int wc_hero_stand_hv_cv_current;
  600. int siop_scenarios_num;
  601. int siop_curr_type_num;
  602. struct sec_siop_table siop_table[SIOP_SCENARIO_NUM_MAX];
  603. int default_input_current;
  604. int default_charging_current;
  605. int default_usb_input_current;
  606. int default_usb_charging_current;
  607. unsigned int default_wc20_input_current;
  608. unsigned int default_wc20_charging_current;
  609. unsigned int default_mpp_input_current;
  610. unsigned int default_mpp_charging_current;
  611. int max_input_voltage;
  612. int max_input_current;
  613. int pre_afc_work_delay;
  614. int pre_wc_afc_work_delay;
  615. unsigned int rp_current_rp1;
  616. unsigned int rp_current_rp2;
  617. unsigned int rp_current_rp3;
  618. unsigned int rp_current_rdu_rp3;
  619. unsigned int rp_current_abnormal_rp3;
  620. bool fake_capacity;
  621. bool en_auto_shipmode_temp_ctrl;
  622. bool boosting_voltage_aicl;
  623. bool tx_5v_disable;
  624. unsigned int phm_vout_ctrl_dev;
  625. unsigned int power_value;
  626. bool bc12_ifcon_wa;
  627. bool mass_with_usb_thm;
  628. bool usb_protection;
  629. /* tx power sharging */
  630. unsigned int tx_stop_capacity;
  631. unsigned int battery_full_capacity;
  632. unsigned int cisd_cap_high_thr;
  633. unsigned int cisd_cap_low_thr;
  634. unsigned int cisd_cap_limit;
  635. int max_voltage_thr;
  636. unsigned int cisd_alg_index;
  637. unsigned int *ignore_cisd_index;
  638. unsigned int *ignore_cisd_index_d;
  639. #if IS_ENABLED(CONFIG_DUAL_BATTERY)
  640. /* zone 1 : 0C ~ 0.4C */
  641. unsigned int zone1_limiter_current;
  642. unsigned int main_zone1_current_rate;
  643. unsigned int sub_zone1_current_rate;
  644. /* zone 2 : 0.4C ~ 1.1C */
  645. unsigned int zone2_limiter_current;
  646. unsigned int main_zone2_current_rate;
  647. unsigned int sub_zone2_current_rate;
  648. /* zone 3 : 1.1C ~ MAX */
  649. unsigned int zone3_limiter_current;
  650. unsigned int main_zone3_current_rate;
  651. unsigned int sub_zone3_current_rate;
  652. unsigned int force_recharge_margin;
  653. unsigned int max_main_limiter_current;
  654. unsigned int min_main_limiter_current;
  655. unsigned int max_sub_limiter_current;
  656. unsigned int min_sub_limiter_current;
  657. /* fully turn on flag */
  658. bool main_fto;
  659. bool sub_fto;
  660. /* fully turn on threshold current */
  661. unsigned int main_fto_current_thresh;
  662. unsigned int sub_fto_current_thresh;
  663. #endif
  664. /* ADC setting */
  665. unsigned int adc_check_count;
  666. unsigned int adc_read_type;
  667. unsigned int full_check_current_1st;
  668. unsigned int full_check_current_2nd;
  669. unsigned int pd_charging_charge_power;
  670. unsigned int nv_charge_power;
  671. unsigned int expired_time;
  672. unsigned int recharging_expired_time;
  673. int standard_curr;
  674. unsigned int tx_minduty_5V;
  675. unsigned int tx_minduty_default;
  676. unsigned int tx_ping_duty_no_ta;
  677. unsigned int tx_ping_duty_default;
  678. unsigned int tx_uno_vout;
  679. unsigned int tx_uno_iout;
  680. unsigned int tx_uno_iout_gear;
  681. unsigned int tx_uno_iout_aov_gear;
  682. unsigned int tx_buds_vout; // true wireless stereo type like buds
  683. unsigned int tx_gear_vout; // watch type
  684. unsigned int tx_ping_vout;
  685. unsigned int tx_mfc_iout_gear;
  686. unsigned int tx_mfc_iout_aov_gear;
  687. unsigned int tx_mfc_iout_phone;
  688. unsigned int tx_mfc_iout_phone_5v;
  689. unsigned int tx_mfc_iout_lcd_on;
  690. unsigned int tx_aov_start_vout;
  691. unsigned int tx_aov_freq_low;
  692. unsigned int tx_aov_freq_high;
  693. unsigned int tx_aov_delay;
  694. unsigned int tx_aov_delay_phm_escape;
  695. /* MAIN LRPST compensation */
  696. bool lr_enable;
  697. unsigned int lr_param_bat_thm;
  698. unsigned int lr_param_sub_bat_thm;
  699. unsigned int lr_delta;
  700. unsigned int lr_param_init_bat_thm;
  701. unsigned int lr_param_init_sub_bat_thm;
  702. unsigned int lr_round_off;
  703. bool wpc_vout_ctrl_lcd_on;
  704. bool soc_by_repcap_en;
  705. unsigned int d2d_check_type;
  706. bool support_vpdo;
  707. bool support_fpdo_dc;
  708. unsigned int fpdo_dc_charge_power;
  709. bool sc_LRP_25W;
  710. int batt_temp_adj_gap_inc;
  711. int change_FV_after_full;
  712. bool support_usb_conn_check;
  713. unsigned int usb_conn_slope_avg;
  714. bool wpc_warm_fod;
  715. unsigned int wpc_warm_fod_icc;
  716. unsigned int wc21_icl;
  717. bool loosened_unknown_temp;
  718. bool support_spsn_ctrl;
  719. bool pogo_chgin;
  720. } sec_battery_platform_data_t;
  721. struct sec_ttf_data;
  722. struct sec_eoc_info {
  723. bool eoc_check;
  724. unsigned int eoc_cnt;
  725. };
  726. struct sec_battery_info {
  727. struct device *dev;
  728. sec_battery_platform_data_t *pdata;
  729. struct sec_ttf_data *ttf_d;
  730. struct sec_eoc_info *eoc_d;
  731. /* power supply used in Android */
  732. struct power_supply *psy_bat;
  733. struct power_supply *psy_usb;
  734. struct power_supply *psy_ac;
  735. struct power_supply *psy_wireless;
  736. struct power_supply *psy_pogo;
  737. struct power_supply *psy_otg;
  738. int pd_usb_attached;
  739. #if IS_ENABLED(CONFIG_USB_TYPEC_MANAGER_NOTIFIER)
  740. struct notifier_block usb_typec_nb;
  741. #else
  742. #if IS_ENABLED(CONFIG_MUIC_NOTIFIER)
  743. struct notifier_block batt_nb;
  744. #endif
  745. #endif
  746. struct notifier_block sb_nb;
  747. bool pdic_attach;
  748. bool pdic_ps_rdy;
  749. bool init_src_cap;
  750. SEC_PD_SINK_STATUS sink_status;
  751. SEC_PD_SINK_STATUS *psink_status;
  752. struct sec_bat_pdic_list pd_list;
  753. bool hv_pdo;
  754. bool update_pd_list;
  755. int d2d_auth;
  756. bool vpdo_src_boost;
  757. bool vpdo_ocp;
  758. int vpdo_auth_stat;
  759. int hp_d2d;
  760. bool is_sysovlo;
  761. bool is_vbatovlo;
  762. bool is_abnormal_temp;
  763. bool safety_timer_set;
  764. bool lcd_status;
  765. bool skip_swelling;
  766. bool wc_auth_retried;
  767. int status;
  768. int health;
  769. bool present;
  770. unsigned int charger_mode;
  771. int voltage_now; /* cell voltage (mV) */
  772. int voltage_avg; /* average voltage (mV) */
  773. int voltage_ocv; /* open circuit voltage (mV) */
  774. int current_now; /* current (mA) */
  775. int inbat_adc; /* inbat adc */
  776. int current_avg; /* average current (mA) */
  777. int current_max; /* input current limit (mA) */
  778. int current_sys; /* system current (mA) */
  779. int current_sys_avg; /* average system current (mA) */
  780. int charge_counter; /* remaining capacity (uAh) */
  781. int current_adc;
  782. int voltage_now_main; /* pack voltage main battery (mV) */
  783. int voltage_now_sub; /* pack voltage sub battery (mV) */
  784. int voltage_avg_main; /* pack voltage main battery (mV) */
  785. int voltage_avg_sub; /* pack voltage sub battery (mV) */
  786. int current_now_main; /* current from main battery (mA) */
  787. int current_now_sub; /* current from sub battery (mA) */
  788. int current_avg_main; /* current from main battery (mA) */
  789. int current_avg_sub; /* current from sub battery (mA) */
  790. #if IS_ENABLED(CONFIG_DUAL_BATTERY)
  791. unsigned int limiter_check;
  792. bool set_lower_curr;
  793. #endif
  794. unsigned int capacity; /* SOC (%) */
  795. #if IS_ENABLED(CONFIG_DUAL_FUELGAUGE)
  796. unsigned int main_capacity; /* MAIN SOC (%) */
  797. unsigned int sub_capacity; /* SUB SOC (%) */
  798. #endif
  799. unsigned int input_voltage; /* CHGIN/WCIN input voltage (V) */
  800. unsigned int charge_power; /* charge power (mW) */
  801. unsigned int max_charge_power; /* max charge power (mW) */
  802. unsigned int pd_max_charge_power; /* max charge power for pd (mW) */
  803. unsigned int pd_rated_power; /* rated power for pd (W) */
  804. /* keep awake until monitor is done */
  805. struct wakeup_source *monitor_ws;
  806. struct workqueue_struct *monitor_wqueue;
  807. struct delayed_work monitor_work;
  808. unsigned int polling_count;
  809. unsigned int polling_time;
  810. bool polling_in_sleep;
  811. bool polling_short;
  812. struct delayed_work polling_work;
  813. struct alarm polling_alarm;
  814. ktime_t last_poll_time;
  815. struct cisd cisd;
  816. bool skip_cisd;
  817. bool usb_overheat_check;
  818. bool otg_check;
  819. bool d2d_check;
  820. int prev_volt;
  821. int prev_temp;
  822. int prev_jig_on;
  823. int enable_update_data;
  824. int prev_chg_on;
  825. #if defined(CONFIG_WIRELESS_AUTH)
  826. sec_bat_misc_dev_t *misc_dev;
  827. #endif
  828. /* battery check */
  829. unsigned int check_count;
  830. /* ADC check */
  831. unsigned int check_adc_count;
  832. unsigned int check_adc_value;
  833. /* health change check*/
  834. bool health_change;
  835. /* ovp-uvlo health check */
  836. int health_check_count;
  837. /* time check */
  838. unsigned long charging_retention_time; /* retention time of charger connection */
  839. unsigned long charging_start_time;
  840. unsigned long charging_passed_time;
  841. unsigned long charging_next_time;
  842. unsigned long charging_fullcharged_time;
  843. unsigned long wc_heating_start_time;
  844. unsigned long wc_heating_passed_time;
  845. /* chg temperature check */
  846. unsigned int chg_limit;
  847. unsigned int chg_limit_recovery_cable;
  848. unsigned int mix_limit;
  849. /* lrp temperature check */
  850. unsigned int lrp_limit;
  851. unsigned int lrp_step;
  852. /* temperature check */
  853. int temperature; /* battery temperature */
  854. #if defined(CONFIG_ENG_BATTERY_CONCEPT)
  855. bool test_max_current;
  856. bool test_charge_current;
  857. #if IS_ENABLED(CONFIG_STEP_CHARGING)
  858. int test_step_condition;
  859. #endif
  860. #endif
  861. int temper_amb; /* target temperature */
  862. int usb_temp;
  863. int chg_temp; /* charger temperature */
  864. int wpc_temp;
  865. int sub_bat_temp;
  866. int usb_conn_status;
  867. int usb_protection_temp;
  868. int temp_gap_bat_usb;
  869. int dchg_temp;
  870. int blkt_temp; /* blanket temperature(instead of batt temp in mix_temp func for tablet model) */
  871. int lrp;
  872. int lrp_test;
  873. unsigned int lrp_chg_src;
  874. int overheatlimit_threshold_backup; /* sec_bat_set_temp_control_test() */
  875. int overheatlimit_recovery_backup; /* sec_bat_set_temp_control_test() */
  876. int overheatlimit_threshold;
  877. int overheatlimit_recovery;
  878. int cold_cool3_thresh;
  879. int cool3_cool2_thresh;
  880. int cool2_cool1_thresh;
  881. int cool1_normal_thresh;
  882. int normal_warm_thresh;
  883. int warm_overheat_thresh;
  884. int thermal_zone;
  885. int bat_thm_count;
  886. int adc_init_count;
  887. /* charging */
  888. unsigned int charging_mode;
  889. bool is_recharging;
  890. int wdt_kick_disable;
  891. bool is_jig_on;
  892. int cable_type;
  893. int muic_cable_type;
  894. bool auto_mode;
  895. struct wakeup_source *cable_ws;
  896. struct delayed_work cable_work;
  897. struct wakeup_source *vbus_ws;
  898. struct wakeup_source *input_ws;
  899. struct delayed_work input_check_work;
  900. #if defined(CONFIG_WIRELESS_FIRMWARE_UPDATE)
  901. struct delayed_work fw_init_work;
  902. #endif
  903. struct delayed_work siop_level_work;
  904. struct wakeup_source *siop_level_ws;
  905. struct wakeup_source *wpc_tx_ws;
  906. struct delayed_work wpc_tx_work;
  907. struct wakeup_source *wpc_tx_en_ws;
  908. struct delayed_work wpc_tx_en_work;
  909. #if defined(CONFIG_UPDATE_BATTERY_DATA)
  910. struct delayed_work batt_data_work;
  911. struct wakeup_source *batt_data_ws;
  912. char *data_path;
  913. #endif
  914. #ifdef CONFIG_OF
  915. struct delayed_work parse_mode_dt_work;
  916. struct wakeup_source *parse_mode_dt_ws;
  917. #endif
  918. struct delayed_work dev_init_work;
  919. struct wakeup_source *dev_init_ws;
  920. struct delayed_work afc_init_work;
  921. struct delayed_work usb_conn_check_work;
  922. struct wakeup_source *usb_conn_check_ws;
  923. struct delayed_work transit_clear_work;
  924. char batt_type[48];
  925. unsigned int full_check_cnt;
  926. unsigned int recharge_check_cnt;
  927. unsigned int input_check_cnt;
  928. unsigned int usb_conn_check_cnt;
  929. bool run_usb_conn_check;
  930. struct mutex iolock;
  931. int input_current;
  932. int charging_current;
  933. #if IS_ENABLED(CONFIG_DUAL_BATTERY)
  934. unsigned int main_current;
  935. unsigned int sub_current;
  936. #endif
  937. int topoff_condition;
  938. int wpc_vout_level;
  939. int wpc_max_vout_level;
  940. unsigned int current_event;
  941. /* wireless charging enable */
  942. struct mutex wclock;
  943. bool wc_enable;
  944. int wc_enable_cnt;
  945. int wc_enable_cnt_value;
  946. int led_cover;
  947. int mag_cover;
  948. int wc_status;
  949. bool wc_cv_mode;
  950. #if defined(CONFIG_WIRELESS_RX_PHM_CTRL)
  951. bool wc_rx_pdetb_mode; // phm state in case of rx mode with models which support pdet_b gpio
  952. #else
  953. bool wc_rx_phm_mode; // phm state in case of rx mode with models which non-support pdet_b gpio
  954. #endif
  955. bool wc_tx_phm_mode; // phm state in case of tx mode
  956. bool prev_tx_phm_mode; // prev phm state in case of tx mode
  957. bool wc_tx_adaptive_vout;
  958. bool wc_need_ldo_on;
  959. int wire_status;
  960. #if IS_ENABLED(CONFIG_MTK_CHARGER) && !IS_ENABLED(CONFIG_VIRTUAL_MUIC)
  961. int bc12_cable;
  962. #endif
  963. /* wireless tx */
  964. bool wc_tx_enable;
  965. bool wc_rx_connected;
  966. bool afc_disable;
  967. bool pd_disable;
  968. bool buck_cntl_by_tx;
  969. bool tx_switch_mode_change;
  970. int wc_tx_vout;
  971. bool uno_en;
  972. unsigned int wc_rx_type;
  973. unsigned int tx_minduty;
  974. unsigned int tx_ping_duty;
  975. unsigned int tx_switch_mode;
  976. unsigned int tx_switch_start_soc;
  977. unsigned int tx_mfc_iout;
  978. unsigned int tx_uno_iout;
  979. int pogo_status;
  980. bool pogo_9v;
  981. /* test mode */
  982. int test_mode;
  983. bool factory_mode;
  984. bool factory_mode_boot_on;
  985. bool display_test;
  986. bool store_mode;
  987. #if defined(CONFIG_BC12_DEVICE) && defined(CONFIG_SEC_FACTORY)
  988. bool vbat_adc_open;
  989. #endif
  990. /* usb suspend */
  991. int prev_usb_conf;
  992. /* MTBF test for CMCC */
  993. bool is_hc_usb;
  994. int siop_level;
  995. int stability_test;
  996. int eng_not_full_status;
  997. int wpc_temp_v2_offset;
  998. bool wpc_vout_ctrl_mode;
  999. char *hv_chg_name;
  1000. #if IS_ENABLED(CONFIG_WIRELESS_CHARGING)
  1001. bool disable_mfc;
  1002. bool nv_wc_temp_ctrl_skip;
  1003. int tx_avg_curr;
  1004. int tx_time_cnt;
  1005. int tx_total_power;
  1006. struct delayed_work wpc_txpower_calc_work;
  1007. bool wc_ept_timeout;
  1008. unsigned int wc20_vout;
  1009. unsigned int wc20_power_class;
  1010. unsigned int wc20_rx_power;
  1011. struct delayed_work wc20_current_work;
  1012. struct delayed_work wc_ept_timeout_work;
  1013. struct wakeup_source *wc20_current_ws;
  1014. struct wakeup_source *wc_ept_timeout_ws;
  1015. #endif
  1016. struct delayed_work slowcharging_work;
  1017. int batt_cycle;
  1018. int batt_asoc;
  1019. int batt_full_status_usage;
  1020. #if IS_ENABLED(CONFIG_STEP_CHARGING)
  1021. bool step_charging_skip_lcd_on;
  1022. bool step_chg_en_in_factory;
  1023. unsigned int step_chg_type;
  1024. unsigned int step_chg_charge_power;
  1025. int step_chg_status;
  1026. int step_chg_step;
  1027. #if IS_ENABLED(CONFIG_WIRELESS_CHARGING)
  1028. unsigned int wpc_step_chg_type;
  1029. unsigned int wpc_step_chg_charge_power;
  1030. int wpc_step_chg_step;
  1031. int wpc_step_chg_status;
  1032. #endif
  1033. #if IS_ENABLED(CONFIG_DIRECT_CHARGING)
  1034. int dc_step_chg_step;
  1035. unsigned int *dc_step_chg_type;
  1036. unsigned int dc_step_chg_charge_power;
  1037. bool dc_float_voltage_set;
  1038. unsigned int dc_step_chg_iin_cnt;
  1039. #endif
  1040. #endif
  1041. bool dchg_dc_in_swelling;
  1042. struct mutex misclock;
  1043. struct mutex txeventlock;
  1044. unsigned int misc_event;
  1045. unsigned int tx_event;
  1046. unsigned int ext_event;
  1047. unsigned int prev_misc_event;
  1048. unsigned int tx_retry_case;
  1049. unsigned int tx_misalign_cnt;
  1050. unsigned int tx_ocp_cnt;
  1051. struct delayed_work ext_event_work;
  1052. struct delayed_work misc_event_work;
  1053. struct wakeup_source *ext_event_ws;
  1054. struct wakeup_source *misc_event_ws;
  1055. struct wakeup_source *tx_event_ws;
  1056. struct mutex batt_handlelock;
  1057. struct mutex current_eventlock;
  1058. struct mutex typec_notylock;
  1059. #if IS_ENABLED(CONFIG_MTK_CHARGER) && !IS_ENABLED(CONFIG_VIRTUAL_MUIC)
  1060. struct mutex bc12_notylock;
  1061. #endif
  1062. struct mutex voutlock;
  1063. unsigned long tx_misalign_start_time;
  1064. unsigned long tx_misalign_passed_time;
  1065. unsigned long tx_ocp_start_time;
  1066. unsigned long tx_ocp_passed_time;
  1067. unsigned int hiccup_status;
  1068. bool hiccup_clear;
  1069. bool stop_timer;
  1070. unsigned long prev_safety_time;
  1071. unsigned long expired_time;
  1072. unsigned long cal_safety_time;
  1073. int fg_reset;
  1074. struct sec_vote *fcc_vote;
  1075. struct sec_vote *input_vote;
  1076. struct sec_vote *fv_vote;
  1077. struct sec_vote *dc_fv_vote;
  1078. struct sec_vote *chgen_vote;
  1079. struct sec_vote *topoff_vote;
  1080. struct sec_vote *iv_vote;
  1081. struct sb_full_soc *fs;
  1082. /* 25w ta alert */
  1083. bool ta_alert_wa;
  1084. int ta_alert_mode;
  1085. bool sleep_mode;
  1086. bool mfc_fw_update;
  1087. int charging_night_mode;
  1088. /* MAIN LRPST compensation */
  1089. unsigned long lr_start_time;
  1090. unsigned long lr_time_span;
  1091. int lrp_temp;
  1092. int lr_bat_t_1;
  1093. bool is_fpdo_dc;
  1094. #if IS_ENABLED(CONFIG_USB_FACTORY_MODE)
  1095. bool usb_factory_init;
  1096. int usb_factory_mode;
  1097. #if defined(CONFIG_SEC_FACTORY)
  1098. bool usb_factory_slate_mode;
  1099. #endif
  1100. unsigned int batt_f_mode;
  1101. #endif
  1102. bool abnormal_ta;
  1103. int srccap_transit_cnt;
  1104. bool srccap_transit;
  1105. int dc_check_cnt;
  1106. bool usb_slow_chg;
  1107. bool usb_bootcomplete;
  1108. unsigned int flash_state;
  1109. unsigned int mst_en;
  1110. #if IS_ENABLED(CONFIG_MTK_CHARGER)
  1111. unsigned int mtk_fg_init;
  1112. #endif
  1113. #if IS_ENABLED(CONFIG_VBUS_NOTIFIER)
  1114. struct notifier_block vbus_nb;
  1115. #endif
  1116. bool is_otg_on;
  1117. bool smart_sw_src;
  1118. };
  1119. enum {
  1120. EXT_DEV_NONE = 0,
  1121. EXT_DEV_GAMEPAD_CHG,
  1122. EXT_DEV_GAMEPAD_OTG,
  1123. };
  1124. #if IS_ENABLED(CONFIG_MTK_CHARGER) && IS_ENABLED(CONFIG_AFC_CHARGER)
  1125. extern int afc_set_voltage(int vol);
  1126. #endif
  1127. extern unsigned int sec_bat_get_lpmode(void);
  1128. extern void sec_bat_set_lpmode(unsigned int value);
  1129. extern int sec_bat_get_fgreset(void);
  1130. extern int sec_bat_get_facmode(void);
  1131. extern unsigned int sec_bat_get_chgmode(void);
  1132. extern void sec_bat_set_chgmode(unsigned int value);
  1133. extern unsigned int sec_bat_get_dispd(void);
  1134. extern void sec_bat_set_dispd(unsigned int value);
  1135. extern int adc_read(struct sec_battery_info *battery, int channel);
  1136. extern void adc_init(struct platform_device *pdev, struct sec_battery_info *battery);
  1137. extern void adc_exit(struct sec_battery_info *battery);
  1138. extern void sec_cable_init(struct platform_device *pdev, struct sec_battery_info *battery);
  1139. extern int sec_bat_get_adc_data(struct device *dev, int adc_ch, int count, int batt_adc_type);
  1140. extern int sec_bat_get_charger_type_adc(struct sec_battery_info *battery);
  1141. extern bool sec_bat_convert_adc_to_val(int adc, int offset,
  1142. sec_bat_adc_table_data_t *adc_table, int size, int *value);
  1143. extern int sec_bat_get_adc_value(struct sec_battery_info *battery, int channel);
  1144. extern int sec_bat_get_inbat_vol_by_adc(struct sec_battery_info *battery);
  1145. extern bool sec_bat_check_vf_adc(struct sec_battery_info *battery);
  1146. #if IS_ENABLED(CONFIG_DIRECT_CHARGING)
  1147. extern int sec_bat_get_direct_chg_temp_adc(struct sec_battery_info *battery, int adc_data, int count, int check_type);
  1148. #endif
  1149. extern void sec_bat_set_misc_event(struct sec_battery_info *battery, unsigned int misc_event_val, unsigned int misc_event_mask);
  1150. extern void sec_bat_set_tx_event(struct sec_battery_info *battery,
  1151. unsigned int tx_event_val, unsigned int tx_event_mask);
  1152. extern void sec_bat_set_current_event(struct sec_battery_info *battery, unsigned int current_event_val, unsigned int current_event_mask);
  1153. extern void sec_bat_set_temp_control_test(struct sec_battery_info *battery, bool temp_enable);
  1154. extern void sec_bat_get_battery_info(struct sec_battery_info *battery);
  1155. extern int sec_bat_set_charging_current(struct sec_battery_info *battery);
  1156. extern void sec_bat_aging_check(struct sec_battery_info *battery);
  1157. extern void sec_bat_set_threshold(struct sec_battery_info *battery, int cable_type);
  1158. extern void sec_bat_thermal_check(struct sec_battery_info *battery);
  1159. extern void sec_bat_set_charging_status(struct sec_battery_info *battery, int status);
  1160. void sec_bat_set_health(struct sec_battery_info *battery, int status);
  1161. extern bool sec_bat_check_full(struct sec_battery_info *battery, int full_check_type);
  1162. extern bool sec_bat_check_fullcharged(struct sec_battery_info *battery);
  1163. extern void sec_bat_check_wpc_temp(struct sec_battery_info *battery, int ct, int siop_level);
  1164. extern void sec_bat_check_wpc_temp_v2(struct sec_battery_info *battery);
  1165. extern void sec_bat_check_mix_temp(struct sec_battery_info *battery, int ct, int siop_level, bool is_apdo);
  1166. extern void sec_bat_check_mix_temp_v2(struct sec_battery_info *battery);
  1167. extern void sec_bat_check_afc_temp(struct sec_battery_info *battery, int siop_level);
  1168. extern void sec_bat_check_pdic_temp(struct sec_battery_info *battery, int siop_level);
  1169. extern void sec_bat_check_direct_chg_temp(struct sec_battery_info *battery, int siop_level);
  1170. extern int sec_bat_check_power_type(int max_chg_pwr, int pd_max_chg_pwr, int ct, int ws, int is_apdo);
  1171. extern void sec_bat_check_lrp_temp(struct sec_battery_info *battery, int ct, int ws, int siop_level, bool lcd_sts);
  1172. extern void sec_bat_check_tx_temperature(struct sec_battery_info *battery);
  1173. extern void sec_bat_change_default_current(struct sec_battery_info *battery, int cable_type, int input, int output);
  1174. extern int sec_bat_set_charge(void *data, int chg_mode);
  1175. extern int adjust_bat_temp(struct sec_battery_info *battery, int batt_temp, int sub_bat_temp);
  1176. extern int get_chg_power_type(int ct, int ws, int pd_max_pw, int max_pw);
  1177. extern int sec_usb_conn_check(struct sec_battery_info *battery);
  1178. #if !defined(CONFIG_SEC_FACTORY)
  1179. extern void sec_bat_check_temp_ctrl_by_cable(struct sec_battery_info *battery);
  1180. #endif
  1181. #if IS_ENABLED(CONFIG_WIRELESS_CHARGING)
  1182. extern void sec_bat_get_wireless_current(struct sec_battery_info *battery);
  1183. extern void sec_bat_mfc_work(struct work_struct *work);
  1184. extern int sec_bat_check_wc_available(struct sec_battery_info *battery);
  1185. extern bool sec_bat_hv_wc_normal_mode_check(struct sec_battery_info *battery);
  1186. extern void sec_bat_ext_event_work_content(struct sec_battery_info *battery);
  1187. extern void sec_bat_wpc_tx_work_content(struct sec_battery_info *battery);
  1188. extern void sec_bat_wpc_tx_en_work_content(struct sec_battery_info *battery);
  1189. extern void sec_bat_set_wc20_current(struct sec_battery_info *battery);
  1190. extern void sec_wireless_otg_vout_control(struct sec_battery_info *battery, int enable);
  1191. extern void sec_wireless_otg_icl_control(struct sec_battery_info *battery);
  1192. extern void sec_bat_set_mfc_off(struct sec_battery_info *battery, char flag, bool need_ept);
  1193. extern void sec_bat_set_mfc_on(struct sec_battery_info *battery, char flag);
  1194. extern int sec_bat_choose_cable_type(struct sec_battery_info *battery);
  1195. extern void sec_bat_handle_tx_misalign(struct sec_battery_info *battery, bool trigger_misalign);
  1196. extern void sec_bat_handle_tx_ocp(struct sec_battery_info *battery, bool trigger_ocp);
  1197. extern void sec_bat_wireless_minduty_cntl(struct sec_battery_info *battery, unsigned int duty_val);
  1198. extern void sec_bat_wireless_uno_cntl(struct sec_battery_info *battery, bool en);
  1199. extern void sec_bat_wireless_iout_cntl(struct sec_battery_info *battery, int uno_iout, int mfc_iout);
  1200. extern void sec_bat_wireless_vout_cntl(struct sec_battery_info *battery, int vout_now);
  1201. extern void sec_bat_check_tx_mode(struct sec_battery_info *battery);
  1202. extern void sec_bat_wc_cv_mode_check(struct sec_battery_info *battery);
  1203. extern void sec_bat_run_wpc_tx_work(struct sec_battery_info *battery, int work_delay);
  1204. extern void sec_bat_txpower_calc(struct sec_battery_info *battery);
  1205. extern void sec_wireless_set_tx_enable(struct sec_battery_info *battery, bool wc_tx_enable);
  1206. extern void sec_bat_check_wc_re_auth(struct sec_battery_info *battery);
  1207. extern unsigned int get_wc20_vout(unsigned int vout);
  1208. extern void sec_bat_mfc_ldo_cntl(struct sec_battery_info *battery, bool en);
  1209. extern int sec_bat_check_wpc_vout(struct sec_battery_info *battery, int ct, unsigned int chg_limit,
  1210. int pre_vout, unsigned int evt);
  1211. #else
  1212. static inline void sec_bat_set_mfc_off(struct sec_battery_info *battery, char flag, bool need_ept) {}
  1213. static inline void sec_bat_set_mfc_on(struct sec_battery_info *battery, char flag) {}
  1214. #endif
  1215. #if defined(CONFIG_WIRELESS_FIRMWARE_UPDATE)
  1216. extern void sec_bat_fw_update(struct sec_battery_info *battery, int mode);
  1217. extern bool sec_bat_check_boost_mfc_condition(struct sec_battery_info *battery, int mode);
  1218. #endif
  1219. #if IS_ENABLED(CONFIG_STEP_CHARGING)
  1220. extern void sec_bat_reset_step_charging(struct sec_battery_info *battery);
  1221. extern void sec_step_charging_init(struct sec_battery_info *battery, struct device *dev);
  1222. extern bool sec_bat_check_step_charging(struct sec_battery_info *battery);
  1223. #if IS_ENABLED(CONFIG_WIRELESS_CHARGING)
  1224. extern bool sec_bat_check_wpc_step_charging(struct sec_battery_info *battery);
  1225. #endif
  1226. #if IS_ENABLED(CONFIG_DIRECT_CHARGING)
  1227. extern bool sec_bat_check_dc_step_charging(struct sec_battery_info *battery);
  1228. #endif
  1229. void sec_bat_set_aging_info_step_charging(struct sec_battery_info *battery);
  1230. #endif
  1231. #if !defined(CONFIG_SEC_FACTORY)
  1232. bool sales_code_is(char *str);
  1233. #endif
  1234. #if defined(CONFIG_UPDATE_BATTERY_DATA)
  1235. extern int sec_battery_update_data(const char* file_path);
  1236. #endif
  1237. extern bool sec_bat_cisd_check(struct sec_battery_info *battery);
  1238. extern void sec_battery_cisd_init(struct sec_battery_info *battery);
  1239. extern void set_cisd_pad_data(struct sec_battery_info *battery, const char* buf);
  1240. extern void set_cisd_power_data(struct sec_battery_info *battery, const char* buf);
  1241. extern void set_cisd_pd_data(struct sec_battery_info *battery, const char *buf);
  1242. #if defined(CONFIG_WIRELESS_AUTH)
  1243. extern int sec_bat_misc_init(struct sec_battery_info *battery);
  1244. #endif
  1245. int sec_bat_parse_dt(struct device *dev, struct sec_battery_info *battery);
  1246. void sec_bat_parse_mode_dt(struct sec_battery_info *battery);
  1247. void sec_bat_parse_mode_dt_work(struct work_struct *work);
  1248. void sec_bat_check_battery_health(struct sec_battery_info *battery);
  1249. bool sec_bat_hv_wc_normal_mode_check(struct sec_battery_info *battery);
  1250. int sec_bat_get_temperature(struct device *dev, struct sec_bat_thm_info *info, int old_val,
  1251. char *chg_name, char *fg_name, int batt_adc_type);
  1252. int sec_bat_get_inbat_vol_ocv(struct sec_battery_info *battery);
  1253. void sec_bat_smart_sw_src(struct sec_battery_info *battery, bool enable, int curr);
  1254. #endif /* __SEC_BATTERY_H */