max77804k_charger.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091
  1. /*
  2. * max77804k_charger.c
  3. * Samsung max77804k Charger Driver
  4. *
  5. * Copyright (C) 2012 Samsung Electronics
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/mfd/max77804k.h>
  13. #include <linux/mfd/max77804k-private.h>
  14. #include <linux/of_gpio.h>
  15. #ifdef CONFIG_USB_HOST_NOTIFY
  16. #include <linux/host_notify.h>
  17. #endif
  18. #ifdef CONFIG_FORCE_FAST_CHARGE
  19. #include <linux/fastchg.h>
  20. #endif
  21. #if defined(CONFIG_MACH_KLTE_CTC)
  22. #include <linux/qpnp/power-on.h>
  23. #endif
  24. #define ENABLE 1
  25. #define DISABLE 0
  26. #define RECOVERY_DELAY 3000
  27. #define RECOVERY_CNT 5
  28. #define REDUCE_CURRENT_STEP 100
  29. #if defined(CONFIG_MACH_HLTEDCM) || defined(CONFIG_MACH_JS01LTEDCM)
  30. #define MINIMUM_INPUT_CURRENT 100
  31. #else
  32. #define MINIMUM_INPUT_CURRENT 300
  33. #endif
  34. #define SIOP_INPUT_LIMIT_CURRENT 1200
  35. #define SIOP_CHARGING_LIMIT_CURRENT 1000
  36. #define SIOP_WIRELESS_INPUT_LIMIT_CURRENT 620
  37. #define SIOP_WIRELESS_CHARGING_LIMIT_CURRENT 680
  38. #define SLOW_CHARGING_CURRENT_STANDARD 400
  39. struct max77804k_charger_data {
  40. struct max77804k_dev *max77804k;
  41. struct power_supply psy_chg;
  42. struct workqueue_struct *wqueue;
  43. struct work_struct chgin_work;
  44. struct delayed_work isr_work;
  45. struct delayed_work recovery_work; /* softreg recovery work */
  46. struct delayed_work wpc_work; /* wpc detect work */
  47. struct delayed_work chgin_init_work; /* chgin init work */
  48. /* mutex */
  49. struct mutex irq_lock;
  50. struct mutex ops_lock;
  51. /* wakelock */
  52. struct wakeup_source recovery_ws;
  53. struct wakeup_source wpc_ws;
  54. struct wakeup_source chgin_ws;
  55. unsigned int is_charging;
  56. unsigned int charging_type;
  57. unsigned int battery_state;
  58. unsigned int battery_present;
  59. unsigned int cable_type;
  60. unsigned int charging_current_max;
  61. unsigned int charging_current;
  62. unsigned int vbus_state;
  63. int aicl_on;
  64. int status;
  65. int siop_level;
  66. int irq_bypass;
  67. #if defined(CONFIG_CHARGER_MAX77804K)
  68. int irq_batp;
  69. #else
  70. int irq_therm;
  71. #endif
  72. int irq_battery;
  73. int irq_chg;
  74. #if defined(CONFIG_CHARGER_MAX77804K)
  75. int irq_wcin;
  76. #endif
  77. int irq_chgin;
  78. /* software regulation */
  79. bool soft_reg_state;
  80. int soft_reg_current;
  81. /* unsufficient power */
  82. bool reg_loop_deted;
  83. #if defined(CONFIG_CHARGER_MAX77804K)
  84. /* wireless charge, w(wpc), v(vbus) */
  85. int wc_w_gpio;
  86. int wc_w_irq;
  87. int wc_w_state;
  88. int wc_v_gpio;
  89. int wc_v_irq;
  90. int wc_v_state;
  91. bool wc_pwr_det;
  92. #endif
  93. int soft_reg_recovery_cnt;
  94. int pmic_ver;
  95. int input_curr_limit_step;
  96. int charging_curr_step;
  97. sec_battery_platform_data_t *pdata;
  98. };
  99. static enum power_supply_property sec_charger_props[] = {
  100. POWER_SUPPLY_PROP_STATUS,
  101. POWER_SUPPLY_PROP_CHARGE_TYPE,
  102. POWER_SUPPLY_PROP_HEALTH,
  103. POWER_SUPPLY_PROP_ONLINE,
  104. POWER_SUPPLY_PROP_CURRENT_MAX,
  105. POWER_SUPPLY_PROP_CURRENT_AVG,
  106. POWER_SUPPLY_PROP_CURRENT_NOW,
  107. POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
  108. #ifdef WPC_CHECK_CVPRM_FEATURE
  109. POWER_SUPPLY_PROP_VOLTAGE_NOW,
  110. #endif
  111. #if defined(CONFIG_BATTERY_SWELLING)
  112. POWER_SUPPLY_PROP_VOLTAGE_MAX,
  113. #endif
  114. };
  115. static void max77804k_charger_initialize(struct max77804k_charger_data *charger);
  116. static int max77804k_get_vbus_state(struct max77804k_charger_data *charger);
  117. static int max77804k_get_charger_state(struct max77804k_charger_data *charger);
  118. static int max77804k_get_byp_dtls(struct max77804k_charger_data *charger);
  119. /*
  120. static void max77804k_dump_reg(struct max77804k_charger_data *charger)
  121. {
  122. u8 reg_data;
  123. u32 reg_addr;
  124. pr_info("%s\n", __func__);
  125. for (reg_addr = 0xB0; reg_addr <= 0xC5; reg_addr++) {
  126. max77804k_read_reg(charger->max77804k->i2c, reg_addr, &reg_data);
  127. pr_info("max77804k: c: 0x%02x(0x%02x)\n", reg_addr, reg_data);
  128. }
  129. }
  130. */
  131. static bool max77804k_charger_unlock(struct max77804k_charger_data *chg_data)
  132. {
  133. struct i2c_client *i2c = chg_data->max77804k->i2c;
  134. u8 reg_data;
  135. u8 chgprot;
  136. int retry_cnt = 0;
  137. bool need_init = false;
  138. do {
  139. max77804k_read_reg(i2c, MAX77804K_CHG_REG_CHG_CNFG_06, &reg_data);
  140. chgprot = ((reg_data & 0x0C) >> 2);
  141. if (chgprot != 0x03) {
  142. pr_err("%s: unlock err, chgprot(0x%x), retry(%d)\n",
  143. __func__, chgprot, retry_cnt);
  144. max77804k_write_reg(i2c, MAX77804K_CHG_REG_CHG_CNFG_06,
  145. (0x03 << 2));
  146. need_init = true;
  147. msleep(20);
  148. } else {
  149. pr_debug("%s: unlock success, chgprot(0x%x)\n",
  150. __func__, chgprot);
  151. break;
  152. }
  153. } while ((chgprot != 0x03) && (++retry_cnt < 10));
  154. return need_init;
  155. }
  156. static void check_charger_unlock_state(struct max77804k_charger_data *chg_data)
  157. {
  158. bool need_reg_init;
  159. pr_debug("%s\n", __func__);
  160. need_reg_init = max77804k_charger_unlock(chg_data);
  161. if (need_reg_init) {
  162. pr_err("%s: charger locked state, reg init\n", __func__);
  163. max77804k_charger_initialize(chg_data);
  164. }
  165. }
  166. static int max77804k_get_battery_present(struct max77804k_charger_data *charger)
  167. {
  168. u8 reg_data;
  169. if (max77804k_read_reg(charger->max77804k->i2c,
  170. MAX77804K_CHG_REG_CHG_INT_OK, &reg_data) < 0) {
  171. /* Eventhough there is an error,
  172. don't do power-off */
  173. return 1;
  174. }
  175. pr_debug("%s: CHG_INT_OK(0x%02x)\n", __func__, reg_data);
  176. #if defined(CONFIG_CHARGER_MAX77804K)
  177. reg_data = ((reg_data & MAX77804K_BATP_OK) >> MAX77804K_BATP_OK_SHIFT);
  178. #else
  179. reg_data = ((reg_data & MAX77804K_DETBAT) >> MAX77804K_DETBAT_SHIFT);
  180. #endif
  181. return reg_data;
  182. }
  183. static void max77804k_set_charger_state(struct max77804k_charger_data *charger,
  184. int enable)
  185. {
  186. u8 reg_data;
  187. pr_debug("%s: enable (%d)\n", __func__, enable);
  188. if (enable)
  189. reg_data = MAX77804K_MODE_CHGR;
  190. else
  191. reg_data = 0x0;
  192. max77804k_update_reg(charger->max77804k->i2c,
  193. MAX77804K_CHG_REG_CHG_CNFG_00, reg_data, MAX77804K_MODE_CHGR);
  194. }
  195. static void max77804k_set_buck(struct max77804k_charger_data *charger,
  196. int enable)
  197. {
  198. u8 reg_data;
  199. pr_debug("%s: enable (%d)\n", __func__, enable);
  200. if (enable)
  201. reg_data = MAX77804K_MODE_BUCK;
  202. else
  203. reg_data = 0x0;
  204. max77804k_update_reg(charger->max77804k->i2c,
  205. MAX77804K_CHG_REG_CHG_CNFG_00, reg_data, MAX77804K_MODE_BUCK);
  206. }
  207. #ifdef WPC_CHECK_CVPRM_FEATURE
  208. static void max77804k_check_cvprm(struct max77804k_charger_data *charger, u8 data)
  209. {
  210. u8 reg_data;
  211. max77804k_read_reg(charger->max77804k->i2c,
  212. MAX77804K_CHG_REG_CHG_CNFG_04, &reg_data);
  213. if ((reg_data & 0x1f) != data) {
  214. reg_data &= ~(0x1f << 0);
  215. reg_data |= (data << 0);
  216. max77804k_write_reg(charger->max77804k->i2c,
  217. MAX77804K_CHG_REG_CHG_CNFG_04, reg_data);
  218. }
  219. }
  220. static int max77804k_get_charge_votage(struct max77804k_charger_data *charger)
  221. {
  222. u8 reg_data;
  223. int charge_voltage;
  224. max77804k_read_reg(charger->max77804k->i2c,
  225. MAX77804K_CHG_REG_CHG_CNFG_04, &reg_data);
  226. reg_data &= 0x1f;
  227. if (reg_data == 0x1c) {
  228. charge_voltage = 4340;
  229. } else {
  230. if (reg_data > 0x1c) {
  231. reg_data -= 1;
  232. }
  233. charge_voltage = (reg_data * 25) + 3650;
  234. }
  235. return charge_voltage;
  236. }
  237. #endif
  238. static void max77804k_check_slow_charging(struct max77804k_charger_data *charger, int set_current_reg)
  239. {
  240. /* under 500mA, slow rate */
  241. if (set_current_reg <= (SLOW_CHARGING_CURRENT_STANDARD / charger->input_curr_limit_step) &&
  242. (charger->cable_type != POWER_SUPPLY_TYPE_BATTERY)) {
  243. charger->aicl_on = true;
  244. pr_info("%s: slow charging on : set_current_reg(0x%02x), cable type(%d)\n", __func__, set_current_reg, charger->cable_type);
  245. }
  246. else
  247. charger->aicl_on = false;
  248. }
  249. static void max77804k_change_charge_path(struct max77804k_charger_data *charger,
  250. int path)
  251. {
  252. u8 cnfg12, ctrl3;
  253. if (path == POWER_SUPPLY_TYPE_WIRELESS) {
  254. cnfg12 = (0 << CHG_CNFG_12_CHGINSEL_SHIFT);
  255. ctrl3 = (1 << CTRL3_JIGSET_SHIFT);
  256. } else {
  257. cnfg12 = (1 << CHG_CNFG_12_CHGINSEL_SHIFT);
  258. ctrl3 = (0 << CTRL3_JIGSET_SHIFT);
  259. }
  260. if (charger->pmic_ver == 0x04)
  261. max77804k_update_reg(charger->max77804k->muic, MAX77804K_MUIC_REG_CTRL3,
  262. ctrl3, CTRL3_JIGSET_MASK);
  263. max77804k_update_reg(charger->max77804k->i2c, MAX77804K_CHG_REG_CHG_CNFG_12,
  264. cnfg12, CHG_CNFG_12_CHGINSEL_MASK);
  265. }
  266. static void max77804k_set_input_current(struct max77804k_charger_data *charger,
  267. int cur)
  268. {
  269. int set_current_reg, now_current_reg;
  270. int byp_dtls, curr_step, delay;
  271. u8 set_reg, reg_data;
  272. int chg_state;
  273. mutex_lock(&charger->ops_lock);
  274. max77804k_update_reg(charger->max77804k->i2c,
  275. MAX77804K_CHG_REG_CHG_INT_MASK, MAX77804K_CHGIN_IM, MAX77804K_CHGIN_IM);
  276. if (charger->cable_type == POWER_SUPPLY_TYPE_WIRELESS) {
  277. set_reg = MAX77804K_CHG_REG_CHG_CNFG_10;
  278. charger->input_curr_limit_step = 20;
  279. } else {
  280. set_reg = MAX77804K_CHG_REG_CHG_CNFG_09;
  281. if (charger->pmic_ver == 0x04)
  282. charger->input_curr_limit_step = 25;
  283. else
  284. charger->input_curr_limit_step = 20;
  285. }
  286. if (cur <= 0) {
  287. /* disable only buck because power onoff test issue */
  288. max77804k_write_reg(charger->max77804k->i2c,
  289. set_reg, 0x19);
  290. #if defined(CONFIG_MACH_KLTE_CTC)
  291. pr_info("%s: qpnp_pon_set_wd_timer 2s\n", __func__);
  292. qpnp_pon_set_wd_timer(1, 1, 0x8);
  293. msleep(10);
  294. #endif
  295. max77804k_set_buck(charger, DISABLE);
  296. #if defined(CONFIG_MACH_KLTE_CTC)
  297. msleep(10);
  298. pr_info("%s: qpnp_pon_set_wd_timer 18s\n", __func__);
  299. qpnp_pon_set_wd_timer(17, 1, 0xE);
  300. #endif
  301. goto exit;
  302. } else {
  303. max77804k_change_charge_path(charger, charger->cable_type);
  304. max77804k_set_buck(charger, ENABLE);
  305. }
  306. set_current_reg = cur / charger->input_curr_limit_step;
  307. if (charger->cable_type == POWER_SUPPLY_TYPE_BATTERY) {
  308. if (charger->status != POWER_SUPPLY_STATUS_CHARGING)
  309. goto set_input_current;
  310. else
  311. goto exit;
  312. }
  313. max77804k_read_reg(charger->max77804k->i2c,
  314. set_reg, &reg_data);
  315. if (reg_data == set_current_reg) {
  316. msleep(50); /* for byp dtls update */
  317. /* check uvlo */
  318. while((set_current_reg > (MINIMUM_INPUT_CURRENT / charger->input_curr_limit_step)) && (set_current_reg < 255)) {
  319. byp_dtls = max77804k_get_byp_dtls(charger);
  320. if ((byp_dtls == 0x08) &&
  321. (charger->cable_type != POWER_SUPPLY_TYPE_WIRELESS)) {
  322. /* UVLO */
  323. set_current_reg -= 5;
  324. if (set_current_reg < (MINIMUM_INPUT_CURRENT / charger->input_curr_limit_step))
  325. set_current_reg = (MINIMUM_INPUT_CURRENT / charger->input_curr_limit_step);
  326. max77804k_write_reg(charger->max77804k->i2c,
  327. set_reg, set_current_reg);
  328. pr_info("%s: set_current_reg(0x%02x)\n", __func__, set_current_reg);
  329. chg_state = max77804k_get_charger_state(charger);
  330. if ((chg_state != POWER_SUPPLY_STATUS_CHARGING) &&
  331. (chg_state != POWER_SUPPLY_STATUS_FULL))
  332. break;
  333. msleep(50);
  334. } else
  335. break;
  336. }
  337. goto exit;
  338. }
  339. if (reg_data == 0) {
  340. now_current_reg = SOFT_CHG_START_CURR / charger->input_curr_limit_step;
  341. max77804k_write_reg(charger->max77804k->i2c,
  342. set_reg, now_current_reg);
  343. msleep(SOFT_CHG_START_DUR);
  344. } else
  345. now_current_reg = reg_data;
  346. if (cur <= 1000) {
  347. curr_step = 1;
  348. delay = 50;
  349. } else {
  350. curr_step = SOFT_CHG_CURR_STEP / charger->input_curr_limit_step;
  351. delay = SOFT_CHG_STEP_DUR;
  352. msleep(30); /* for byp dtls update */
  353. }
  354. now_current_reg += (curr_step);
  355. while (now_current_reg < set_current_reg &&
  356. charger->cable_type != POWER_SUPPLY_TYPE_BATTERY)
  357. {
  358. now_current_reg = min(now_current_reg, set_current_reg);
  359. max77804k_write_reg(charger->max77804k->i2c,
  360. set_reg, now_current_reg);
  361. msleep(delay);
  362. byp_dtls = max77804k_get_byp_dtls(charger);
  363. if ((byp_dtls == 0x08) &&
  364. (charger->cable_type != POWER_SUPPLY_TYPE_WIRELESS)) {
  365. /* UVLO */
  366. if (now_current_reg > (curr_step * 3))
  367. now_current_reg -= (curr_step * 3);
  368. /* current limit 300mA */
  369. if (now_current_reg < (MINIMUM_INPUT_CURRENT / charger->input_curr_limit_step))
  370. now_current_reg = (MINIMUM_INPUT_CURRENT / charger->input_curr_limit_step);
  371. curr_step /= 2;
  372. max77804k_write_reg(charger->max77804k->i2c,
  373. set_reg, now_current_reg);
  374. pr_info("%s: now_current_reg(0x%02x)\n", __func__, now_current_reg);
  375. chg_state = max77804k_get_charger_state(charger);
  376. if ((chg_state != POWER_SUPPLY_STATUS_CHARGING) &&
  377. (chg_state != POWER_SUPPLY_STATUS_FULL))
  378. goto exit;
  379. if (curr_step < 2) {
  380. goto exit;
  381. }
  382. msleep(50);
  383. } else
  384. now_current_reg += (curr_step);
  385. }
  386. set_input_current:
  387. pr_info("%s: reg_data(0x%02x), input(%d)\n",
  388. __func__, set_current_reg, cur);
  389. max77804k_write_reg(charger->max77804k->i2c,
  390. set_reg, set_current_reg);
  391. exit:
  392. /* slow charging check */
  393. max77804k_read_reg(charger->max77804k->i2c,
  394. set_reg, &reg_data);
  395. max77804k_check_slow_charging(charger, reg_data);
  396. max77804k_update_reg(charger->max77804k->i2c,
  397. MAX77804K_CHG_REG_CHG_INT_MASK, 0, MAX77804K_CHGIN_IM);
  398. mutex_unlock(&charger->ops_lock);
  399. }
  400. static int max77804k_get_input_current(struct max77804k_charger_data *charger)
  401. {
  402. u8 reg_data;
  403. int get_current = 0;
  404. if (charger->cable_type == POWER_SUPPLY_TYPE_WIRELESS) {
  405. max77804k_read_reg(charger->max77804k->i2c,
  406. MAX77804K_CHG_REG_CHG_CNFG_10, &reg_data);
  407. pr_info("%s: CHG_CNFG_10(0x%02x)\n", __func__, reg_data);
  408. /* AND operation for removing the formal 2bit */
  409. reg_data = reg_data & 0x3F;
  410. charger->input_curr_limit_step = 20;
  411. } else {
  412. max77804k_read_reg(charger->max77804k->i2c,
  413. MAX77804K_CHG_REG_CHG_CNFG_09, &reg_data);
  414. pr_info("%s: CHG_CNFG_09(0x%02x)\n", __func__, reg_data);
  415. /* AND operation for removing the formal 1bit */
  416. reg_data = reg_data & 0x7F;
  417. if (charger->pmic_ver == 0x04)
  418. charger->input_curr_limit_step = 25;
  419. else
  420. charger->input_curr_limit_step = 20;
  421. }
  422. get_current = reg_data * charger->input_curr_limit_step;
  423. pr_debug("%s: get input current: %dmA\n", __func__, get_current);
  424. return get_current;
  425. }
  426. static void max77804k_set_topoff_current(struct max77804k_charger_data *charger,
  427. int cur, int timeout)
  428. {
  429. u8 reg_data;
  430. if (cur >= 350)
  431. reg_data = 0x07;
  432. else if (cur >= 300)
  433. reg_data = 0x06;
  434. else if (cur >= 250)
  435. reg_data = 0x05;
  436. else if (cur >= 200)
  437. reg_data = 0x04;
  438. else if (cur >= 175)
  439. reg_data = 0x03;
  440. else if (cur >= 150)
  441. reg_data = 0x02;
  442. else if (cur >= 125)
  443. reg_data = 0x01;
  444. else
  445. reg_data = 0x00;
  446. /* the unit of timeout is second*/
  447. timeout = timeout / 60;
  448. reg_data |= ((timeout / 10) << 3);
  449. pr_info("%s: reg_data(0x%02x), topoff(%d)\n", __func__, reg_data, cur);
  450. max77804k_write_reg(charger->max77804k->i2c,
  451. MAX77804K_CHG_REG_CHG_CNFG_03, reg_data);
  452. }
  453. static void max77804k_set_charge_current(struct max77804k_charger_data *charger,
  454. int cur)
  455. {
  456. u8 reg_data = 0;
  457. max77804k_read_reg(charger->max77804k->i2c,
  458. MAX77804K_CHG_REG_CHG_CNFG_02, &reg_data);
  459. reg_data &= ~MAX77804K_CHG_CC;
  460. if (!cur) {
  461. /* No charger */
  462. max77804k_write_reg(charger->max77804k->i2c,
  463. MAX77804K_CHG_REG_CHG_CNFG_02, reg_data);
  464. } else {
  465. reg_data |= ((cur * 10 / charger->charging_curr_step) << 0);
  466. max77804k_write_reg(charger->max77804k->i2c,
  467. MAX77804K_CHG_REG_CHG_CNFG_02, reg_data);
  468. }
  469. pr_info("%s: reg_data(0x%02x), charge(%d)\n",
  470. __func__, reg_data, cur);
  471. }
  472. /*
  473. static int max77804k_get_charge_current(struct max77804k_charger_data *charger)
  474. {
  475. u8 reg_data;
  476. int get_current;
  477. max77804k_read_reg(charger->max77804k->i2c,
  478. MAX77804K_CHG_REG_CHG_CNFG_02, &reg_data);
  479. pr_debug("%s: CHG_CNFG_02(0x%02x)\n", __func__, reg_data);
  480. reg_data &= MAX77804K_CHG_CC;
  481. get_current = reg_data * charger->charging_curr_step / 10;
  482. pr_debug("%s: get charge current: %dmA\n", __func__, get_current);
  483. return get_current;
  484. }
  485. */
  486. /* in soft regulation, current recovery operation */
  487. static void max77804k_recovery_work(struct work_struct *work)
  488. {
  489. struct max77804k_charger_data *chg_data = container_of(work,
  490. struct max77804k_charger_data,
  491. recovery_work.work);
  492. u8 dtls_00, chgin_dtls;
  493. u8 dtls_01, chg_dtls;
  494. u8 dtls_02, byp_dtls;
  495. pr_debug("%s\n", __func__);
  496. __pm_relax(&chg_data->recovery_ws);
  497. if ((!chg_data->is_charging) || mutex_is_locked(&chg_data->ops_lock) ||
  498. (chg_data->cable_type != POWER_SUPPLY_TYPE_MAINS))
  499. return;
  500. max77804k_read_reg(chg_data->max77804k->i2c,
  501. MAX77804K_CHG_REG_CHG_DTLS_00, &dtls_00);
  502. max77804k_read_reg(chg_data->max77804k->i2c,
  503. MAX77804K_CHG_REG_CHG_DTLS_01, &dtls_01);
  504. max77804k_read_reg(chg_data->max77804k->i2c,
  505. MAX77804K_CHG_REG_CHG_DTLS_02, &dtls_02);
  506. chgin_dtls = ((dtls_00 & MAX77804K_CHGIN_DTLS) >>
  507. MAX77804K_CHGIN_DTLS_SHIFT);
  508. chg_dtls = ((dtls_01 & MAX77804K_CHG_DTLS) >>
  509. MAX77804K_CHG_DTLS_SHIFT);
  510. byp_dtls = ((dtls_02 & MAX77804K_BYP_DTLS) >>
  511. MAX77804K_BYP_DTLS_SHIFT);
  512. if ((chg_data->soft_reg_recovery_cnt < RECOVERY_CNT) && (
  513. (chgin_dtls == 0x3) && (chg_dtls != 0x8) && (byp_dtls == 0x0))) {
  514. pr_info("%s: try to recovery, cnt(%d)\n", __func__,
  515. (chg_data->soft_reg_recovery_cnt + 1));
  516. if (chg_data->siop_level < 100 &&
  517. chg_data->cable_type == POWER_SUPPLY_TYPE_MAINS) {
  518. pr_info("%s : LCD on status and recover current\n", __func__);
  519. max77804k_set_input_current(chg_data,
  520. SIOP_INPUT_LIMIT_CURRENT);
  521. } else {
  522. max77804k_set_input_current(chg_data,
  523. chg_data->charging_current_max);
  524. }
  525. } else {
  526. pr_info("%s: fail to recovery, cnt(%d)\n", __func__,
  527. (chg_data->soft_reg_recovery_cnt + 1));
  528. pr_info("%s: CHGIN(0x%x), CHG(0x%x), BYP(0x%x)\n",
  529. __func__, chgin_dtls, chg_dtls, byp_dtls);
  530. /* schedule softreg recovery wq */
  531. if (chg_data->soft_reg_recovery_cnt < RECOVERY_CNT) {
  532. __pm_stay_awake(&chg_data->recovery_ws);
  533. queue_delayed_work(chg_data->wqueue, &chg_data->recovery_work,
  534. msecs_to_jiffies(RECOVERY_DELAY));
  535. } else {
  536. pr_info("%s: recovery cnt(%d) is over\n",
  537. __func__, RECOVERY_CNT);
  538. }
  539. }
  540. /* add recovery try count */
  541. chg_data->soft_reg_recovery_cnt++;
  542. }
  543. static void reduce_input_current(struct max77804k_charger_data *charger, int cur)
  544. {
  545. u8 set_reg;
  546. u8 set_value;
  547. unsigned int min_input_current = 0;
  548. if ((!charger->is_charging) || mutex_is_locked(&charger->ops_lock) ||
  549. (charger->cable_type == POWER_SUPPLY_TYPE_WIRELESS))
  550. return;
  551. set_reg = MAX77804K_CHG_REG_CHG_CNFG_09;
  552. min_input_current = MINIMUM_INPUT_CURRENT;
  553. if (charger->pmic_ver == 0x04)
  554. charger->input_curr_limit_step = 25;
  555. else
  556. charger->input_curr_limit_step = 20;
  557. if (!max77804k_read_reg(charger->max77804k->i2c,
  558. set_reg, &set_value)) {
  559. if ((set_value <= (min_input_current / charger->input_curr_limit_step)) ||
  560. (set_value <= (cur / charger->input_curr_limit_step)))
  561. return;
  562. set_value -= (cur / charger->input_curr_limit_step);
  563. set_value = (set_value < (min_input_current / charger->input_curr_limit_step)) ?
  564. (min_input_current / charger->input_curr_limit_step) : set_value;
  565. max77804k_write_reg(charger->max77804k->i2c,
  566. set_reg, set_value);
  567. pr_info("%s: set current: reg:(0x%x), val:(0x%x)\n",
  568. __func__, set_reg, set_value);
  569. }
  570. if(charger->cable_type == POWER_SUPPLY_TYPE_MAINS) {
  571. /* schedule softreg recovery wq */
  572. cancel_delayed_work_sync(&charger->recovery_work);
  573. __pm_stay_awake(&charger->recovery_ws);
  574. queue_delayed_work(charger->wqueue, &charger->recovery_work,
  575. msecs_to_jiffies(RECOVERY_DELAY));
  576. }
  577. }
  578. static int max77804k_get_vbus_state(struct max77804k_charger_data *charger)
  579. {
  580. u8 reg_data;
  581. union power_supply_propval value;
  582. max77804k_read_reg(charger->max77804k->i2c,
  583. MAX77804K_CHG_REG_CHG_DTLS_00, &reg_data);
  584. psy_do_property("battery", get, POWER_SUPPLY_PROP_ONLINE,
  585. value);
  586. if (value.intval == POWER_SUPPLY_TYPE_WIRELESS || \
  587. (charger->pdata->use_wireless_to_pogo && \
  588. value.intval == POWER_SUPPLY_TYPE_POGODOCK))
  589. reg_data = ((reg_data & MAX77804K_WCIN_DTLS) >>
  590. MAX77804K_WCIN_DTLS_SHIFT);
  591. else
  592. reg_data = ((reg_data & MAX77804K_CHGIN_DTLS) >>
  593. MAX77804K_CHGIN_DTLS_SHIFT);
  594. switch (reg_data) {
  595. case 0x00:
  596. pr_info("%s: VBUS is invalid. CHGIN < CHGIN_UVLO\n",
  597. __func__);
  598. break;
  599. case 0x01:
  600. pr_info("%s: VBUS is invalid. CHGIN < MBAT+CHGIN2SYS" \
  601. "and CHGIN > CHGIN_UVLO\n", __func__);
  602. break;
  603. case 0x02:
  604. pr_info("%s: VBUS is invalid. CHGIN > CHGIN_OVLO",
  605. __func__);
  606. break;
  607. case 0x03:
  608. break;
  609. default:
  610. break;
  611. }
  612. return reg_data;
  613. }
  614. static int max77804k_get_byp_dtls(struct max77804k_charger_data *charger)
  615. {
  616. u8 reg_data;
  617. max77804k_read_reg(charger->max77804k->i2c,
  618. MAX77804K_CHG_REG_CHG_DTLS_02,
  619. &reg_data);
  620. reg_data = ((reg_data & MAX77804K_BYP_DTLS) >>
  621. MAX77804K_BYP_DTLS_SHIFT);
  622. pr_info("%s: BYP_DTLS : 0x%2x\n", __func__, reg_data);
  623. return reg_data;
  624. }
  625. static int max77804k_get_charger_state(struct max77804k_charger_data *charger)
  626. {
  627. int state;
  628. u8 reg_data;
  629. max77804k_read_reg(charger->max77804k->i2c,
  630. MAX77804K_CHG_REG_CHG_DTLS_01, &reg_data);
  631. reg_data = ((reg_data & MAX77804K_CHG_DTLS) >> MAX77804K_CHG_DTLS_SHIFT);
  632. pr_info("%s: CHG_DTLS : 0x%2x\n", __func__, reg_data);
  633. switch (reg_data) {
  634. case 0x0:
  635. case 0x1:
  636. case 0x2:
  637. state = POWER_SUPPLY_STATUS_CHARGING;
  638. break;
  639. case 0x3:
  640. case 0x4:
  641. state = POWER_SUPPLY_STATUS_FULL;
  642. break;
  643. case 0x5:
  644. case 0x6:
  645. case 0x7:
  646. state = POWER_SUPPLY_STATUS_NOT_CHARGING;
  647. break;
  648. case 0x8:
  649. case 0xA:
  650. case 0xB:
  651. state = POWER_SUPPLY_STATUS_DISCHARGING;
  652. break;
  653. default:
  654. state = POWER_SUPPLY_STATUS_UNKNOWN;
  655. break;
  656. }
  657. return state;
  658. }
  659. static int max77804k_get_health_state(struct max77804k_charger_data *charger)
  660. {
  661. int state;
  662. int vbus_state;
  663. int retry_cnt;
  664. u8 chg_int_mask, chg_dtls_00, chg_dtls, reg_data;
  665. u8 chg_cnfg_00, chg_cnfg_01 ,chg_cnfg_02, chg_cnfg_04, chg_cnfg_09, chg_cnfg_12;
  666. max77804k_read_reg(charger->max77804k->i2c,
  667. MAX77804K_CHG_REG_CHG_DTLS_01, &reg_data);
  668. max77804k_read_reg(charger->max77804k->i2c,
  669. MAX77804K_CHG_REG_CHG_INT_MASK, &chg_int_mask);
  670. reg_data = ((reg_data & MAX77804K_BAT_DTLS) >> MAX77804K_BAT_DTLS_SHIFT);
  671. pr_info("%s: bat_dtls(0x%x) int_mask(0x%x)\n", __func__, reg_data, chg_int_mask);
  672. switch (reg_data) {
  673. case 0x00:
  674. pr_info("%s: No battery and the charger is suspended\n",
  675. __func__);
  676. state = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
  677. break;
  678. case 0x01:
  679. pr_info("%s: battery is okay "
  680. "but its voltage is low(~VPQLB)\n", __func__);
  681. state = POWER_SUPPLY_HEALTH_GOOD;
  682. break;
  683. case 0x02:
  684. pr_info("%s: battery dead\n", __func__);
  685. state = POWER_SUPPLY_HEALTH_DEAD;
  686. break;
  687. case 0x03:
  688. state = POWER_SUPPLY_HEALTH_GOOD;
  689. break;
  690. case 0x04:
  691. pr_info("%s: battery is okay" \
  692. "but its voltage is low\n", __func__);
  693. state = POWER_SUPPLY_HEALTH_GOOD;
  694. break;
  695. case 0x05:
  696. pr_info("%s: battery ovp\n", __func__);
  697. state = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
  698. break;
  699. default:
  700. pr_info("%s: battery unknown : 0x%d\n", __func__, reg_data);
  701. state = POWER_SUPPLY_HEALTH_UNKNOWN;
  702. break;
  703. }
  704. if (state == POWER_SUPPLY_HEALTH_GOOD) {
  705. union power_supply_propval value;
  706. psy_do_property("battery", get,
  707. POWER_SUPPLY_PROP_HEALTH, value);
  708. /* VBUS OVP state return battery OVP state */
  709. vbus_state = max77804k_get_vbus_state(charger);
  710. /* read CHG_DTLS and detecting battery terminal error */
  711. max77804k_read_reg(charger->max77804k->i2c,
  712. MAX77804K_CHG_REG_CHG_DTLS_01, &chg_dtls);
  713. chg_dtls = ((chg_dtls & MAX77804K_CHG_DTLS) >>
  714. MAX77804K_CHG_DTLS_SHIFT);
  715. max77804k_read_reg(charger->max77804k->i2c,
  716. MAX77804K_CHG_REG_CHG_CNFG_00, &chg_cnfg_00);
  717. /* print the log at the abnormal case */
  718. if((charger->is_charging == 1) && (chg_dtls & 0x08)) {
  719. max77804k_read_reg(charger->max77804k->i2c,
  720. MAX77804K_CHG_REG_CHG_DTLS_00, &chg_dtls_00);
  721. max77804k_read_reg(charger->max77804k->i2c,
  722. MAX77804K_CHG_REG_CHG_CNFG_01, &chg_cnfg_01);
  723. max77804k_read_reg(charger->max77804k->i2c,
  724. MAX77804K_CHG_REG_CHG_CNFG_02, &chg_cnfg_02);
  725. max77804k_read_reg(charger->max77804k->i2c,
  726. MAX77804K_CHG_REG_CHG_CNFG_04, &chg_cnfg_04);
  727. max77804k_read_reg(charger->max77804k->i2c,
  728. MAX77804K_CHG_REG_CHG_CNFG_09, &chg_cnfg_09);
  729. max77804k_read_reg(charger->max77804k->i2c,
  730. MAX77804K_CHG_REG_CHG_CNFG_12, &chg_cnfg_12);
  731. pr_info("%s: CHG_DTLS_00(0x%x), CHG_DTLS_01(0x%x), CHG_CNFG_00(0x%x)\n",
  732. __func__, chg_dtls_00, chg_dtls, chg_cnfg_00);
  733. pr_info("%s: CHG_CNFG_01(0x%x), CHG_CNFG_02(0x%x), CHG_CNFG_04(0x%x)\n",
  734. __func__, chg_cnfg_01, chg_cnfg_02, chg_cnfg_04);
  735. pr_info("%s: CHG_CNFG_09(0x%x), CHG_CNFG_12(0x%x)\n",
  736. __func__, chg_cnfg_09, chg_cnfg_12);
  737. }
  738. pr_info("%s: vbus_state : 0x%d, chg_dtls : 0x%d\n", __func__, vbus_state, chg_dtls);
  739. /* OVP is higher priority */
  740. if (vbus_state == 0x02) { /* CHGIN_OVLO */
  741. pr_info("%s: vbus ovp\n", __func__);
  742. state = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
  743. if (charger->cable_type == POWER_SUPPLY_TYPE_WIRELESS) {
  744. retry_cnt = 0;
  745. do {
  746. msleep(50);
  747. vbus_state = max77804k_get_vbus_state(charger);
  748. } while((retry_cnt++ < 2) && (vbus_state == 0x02));
  749. if (vbus_state == 0x02) {
  750. state = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
  751. pr_info("%s: wpc and over-voltage\n", __func__);
  752. } else
  753. state = POWER_SUPPLY_HEALTH_GOOD;
  754. }
  755. } else if (((vbus_state == 0x0) || (vbus_state == 0x01)) &&(chg_dtls & 0x08) && \
  756. (chg_cnfg_00 & MAX77804K_MODE_BUCK) && \
  757. (chg_cnfg_00 & MAX77804K_MODE_CHGR) && \
  758. (charger->cable_type != POWER_SUPPLY_TYPE_WIRELESS)) {
  759. pr_info("%s: vbus is under\n", __func__);
  760. state = POWER_SUPPLY_HEALTH_UNDERVOLTAGE;
  761. } else if((value.intval == POWER_SUPPLY_HEALTH_UNDERVOLTAGE) && \
  762. !((vbus_state == 0x0) || (vbus_state == 0x01))){
  763. max77804k_set_input_current(charger,
  764. charger->charging_current_max);
  765. }
  766. if (chg_int_mask & MAX77804K_WCIN_IM) {
  767. pr_info("%s: unmask wcin int\n", __func__);
  768. max77804k_update_reg(charger->max77804k->i2c,
  769. MAX77804K_CHG_REG_CHG_INT_MASK, 0, MAX77804K_WCIN_IM);
  770. }
  771. }
  772. return state;
  773. }
  774. static int sec_chg_get_property(struct power_supply *psy,
  775. enum power_supply_property psp,
  776. union power_supply_propval *val)
  777. {
  778. struct max77804k_charger_data *charger =
  779. container_of(psy, struct max77804k_charger_data, psy_chg);
  780. u8 reg_data;
  781. switch (psp) {
  782. case POWER_SUPPLY_PROP_ONLINE:
  783. val->intval = POWER_SUPPLY_TYPE_BATTERY;
  784. if (max77804k_read_reg(charger->max77804k->i2c,
  785. MAX77804K_CHG_REG_CHG_INT_OK, &reg_data) == 0) {
  786. pr_info("%s: reg_data(%d)\n", __func__, reg_data);
  787. if (reg_data & MAX77804K_WCIN_OK) {
  788. val->intval = POWER_SUPPLY_TYPE_WIRELESS;
  789. charger->wc_w_state = 1;
  790. } else if (reg_data & MAX77804K_CHGIN_OK) {
  791. val->intval = POWER_SUPPLY_TYPE_MAINS;
  792. }
  793. }
  794. break;
  795. case POWER_SUPPLY_PROP_STATUS:
  796. val->intval = max77804k_get_charger_state(charger);
  797. break;
  798. case POWER_SUPPLY_PROP_HEALTH:
  799. val->intval = max77804k_get_health_state(charger);
  800. break;
  801. case POWER_SUPPLY_PROP_CURRENT_MAX:
  802. // AOSP expects the charging current to be in microamperes
  803. // frameworks/base/core/java/android/os/BatteryManager.java L256
  804. val->intval = charger->charging_current_max * 1000;
  805. break;
  806. case POWER_SUPPLY_PROP_CURRENT_AVG:
  807. // AOSP expects the charging current to be in microamperes
  808. // frameworks/base/core/java/android/os/BatteryManager.java L263
  809. val->intval = charger->charging_current * 1000;
  810. break;
  811. case POWER_SUPPLY_PROP_CURRENT_NOW:
  812. val->intval = max77804k_get_input_current(charger);
  813. break;
  814. case POWER_SUPPLY_PROP_CHARGE_TYPE:
  815. if (!charger->is_charging)
  816. val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
  817. else if (charger->aicl_on)
  818. {
  819. val->intval = POWER_SUPPLY_CHARGE_TYPE_SLOW;
  820. pr_info("%s: slow-charging mode\n", __func__);
  821. }
  822. else
  823. val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST;
  824. break;
  825. case POWER_SUPPLY_PROP_PRESENT:
  826. val->intval = max77804k_get_battery_present(charger);
  827. break;
  828. case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
  829. break;
  830. #ifdef WPC_CHECK_CVPRM_FEATURE
  831. case POWER_SUPPLY_PROP_VOLTAGE_NOW:
  832. val->intval = max77804k_get_charge_votage(charger);
  833. break;
  834. #endif
  835. #if defined(CONFIG_BATTERY_SWELLING)
  836. case POWER_SUPPLY_PROP_VOLTAGE_MAX:
  837. max77804k_read_reg(charger->max77804k->i2c,MAX77804K_CHG_REG_CHG_CNFG_04, &reg_data);
  838. val->intval = reg_data;
  839. pr_info("%s: Float voltage : 0x%x\n", __func__, val->intval);
  840. break;
  841. #endif
  842. default:
  843. return -EINVAL;
  844. }
  845. return 0;
  846. }
  847. static u8 max77804k_get_float_voltage_data(int float_voltage);
  848. static int sec_chg_set_property(struct power_supply *psy,
  849. enum power_supply_property psp,
  850. const union power_supply_propval *val)
  851. {
  852. struct max77804k_charger_data *charger =
  853. container_of(psy, struct max77804k_charger_data, psy_chg);
  854. union power_supply_propval value;
  855. int set_charging_current, set_charging_current_max;
  856. const int usb_charging_current = charger->pdata->charging_current[
  857. POWER_SUPPLY_TYPE_USB].fast_charging_current;
  858. u8 chg_cnfg_00;
  859. #if defined(CONFIG_BATTERY_SWELLING)
  860. u8 reg_data;
  861. #endif
  862. switch (psp) {
  863. case POWER_SUPPLY_PROP_STATUS:
  864. charger->status = val->intval;
  865. break;
  866. /* val->intval : type */
  867. case POWER_SUPPLY_PROP_ONLINE:
  868. /* check and unlock */
  869. check_charger_unlock_state(charger);
  870. if (val->intval == POWER_SUPPLY_TYPE_POWER_SHARING) {
  871. psy_do_property("ps", get,
  872. POWER_SUPPLY_PROP_STATUS, value);
  873. chg_cnfg_00 = CHG_CNFG_00_OTG_MASK
  874. | CHG_CNFG_00_BOOST_MASK
  875. | CHG_CNFG_00_DIS_MUIC_CTRL_MASK;
  876. if (value.intval) {
  877. max77804k_update_reg(charger->max77804k->i2c, MAX77804K_CHG_REG_CHG_CNFG_00,
  878. chg_cnfg_00, chg_cnfg_00);
  879. pr_info("%s: ps enable\n", __func__);
  880. } else {
  881. max77804k_update_reg(charger->max77804k->i2c, MAX77804K_CHG_REG_CHG_CNFG_00,
  882. 0, chg_cnfg_00);
  883. pr_info("%s: ps disable\n", __func__);
  884. }
  885. break;
  886. }
  887. charger->cable_type = val->intval;
  888. psy_do_property("battery", get,
  889. POWER_SUPPLY_PROP_HEALTH, value);
  890. if (val->intval == POWER_SUPPLY_TYPE_BATTERY) {
  891. charger->is_charging = false;
  892. charger->aicl_on = false;
  893. charger->soft_reg_recovery_cnt = 0;
  894. set_charging_current = 0;
  895. set_charging_current_max =
  896. charger->pdata->charging_current[
  897. POWER_SUPPLY_TYPE_USB].input_current_limit;
  898. } else {
  899. charger->is_charging = true;
  900. charger->charging_current_max =
  901. charger->pdata->charging_current
  902. [charger->cable_type].input_current_limit;
  903. charger->charging_current =
  904. charger->pdata->charging_current
  905. [charger->cable_type].fast_charging_current;
  906. #ifdef CONFIG_FORCE_FAST_CHARGE
  907. /* Yank555 : Use Fast charge currents accroding to user settings */
  908. if (force_fast_charge == FAST_CHARGE_FORCE_AC) {/* We are in basic Fast Charge mode, so we substitute AC to USB levels */
  909. switch(charger->cable_type) {
  910. case POWER_SUPPLY_TYPE_USB: /* These are low current USB connections, apply usual 1A/h AC levels to USB */
  911. case POWER_SUPPLY_TYPE_USB_ACA:
  912. case POWER_SUPPLY_TYPE_CARDOCK:
  913. case POWER_SUPPLY_TYPE_OTG: charger->charging_current_max = USB_CHARGE_1000;
  914. charger->charging_current = USB_CHARGE_1000;
  915. break;
  916. default: /* Don't do anything for any other kind of connections and don't touch when type is unknown */
  917. break;
  918. }
  919. } else if (force_fast_charge == FAST_CHARGE_FORCE_CUSTOM_MA) { /* We are in custom current Fast Charge mode for both AC and USB */
  920. switch(charger->cable_type) {
  921. case POWER_SUPPLY_TYPE_USB:
  922. case POWER_SUPPLY_TYPE_USB_DCP:
  923. case POWER_SUPPLY_TYPE_USB_CDP:
  924. case POWER_SUPPLY_TYPE_USB_ACA:
  925. case POWER_SUPPLY_TYPE_CARDOCK:
  926. case POWER_SUPPLY_TYPE_OTG: /* These are USB connections, apply custom USB current for all of them */
  927. charger->charging_current_max = usb_charge_level;
  928. charger->charging_current = usb_charge_level;
  929. break;
  930. case POWER_SUPPLY_TYPE_MAINS: /* These are AC connections, apply custom AC current for all of them */
  931. charger->charging_current_max = ac_charge_level;
  932. charger->charging_current = min(ac_charge_level+300, MAX_CHARGE_LEVEL); /* Keep the 300mA/h delta, but never go above 2.1A/h */
  933. break;
  934. default: /* Don't do anything for any other kind of connections and don't touch when type is unknown */
  935. break;
  936. }
  937. }
  938. #endif // CONFIG_FORCE_FAST_CHARGE
  939. /* decrease the charging current according to siop level */
  940. set_charging_current =
  941. charger->charging_current * charger->siop_level / 100;
  942. if (set_charging_current > 0 &&
  943. set_charging_current < usb_charging_current)
  944. set_charging_current = usb_charging_current;
  945. set_charging_current_max =
  946. charger->charging_current_max;
  947. #ifdef WPC_CHECK_CVPRM_FEATURE
  948. if (val->intval == POWER_SUPPLY_TYPE_WIRELESS)
  949. max77804k_check_cvprm(charger, 0x1C);
  950. else
  951. max77804k_check_cvprm(charger, 0x1D);
  952. #endif
  953. if (charger->siop_level < 100) {
  954. if (val->intval == POWER_SUPPLY_TYPE_WIRELESS) {
  955. if (set_charging_current_max > SIOP_WIRELESS_INPUT_LIMIT_CURRENT) {
  956. set_charging_current_max = SIOP_WIRELESS_INPUT_LIMIT_CURRENT;
  957. if (set_charging_current > SIOP_WIRELESS_CHARGING_LIMIT_CURRENT)
  958. set_charging_current = SIOP_WIRELESS_CHARGING_LIMIT_CURRENT;
  959. }
  960. } else {
  961. if (set_charging_current_max > SIOP_INPUT_LIMIT_CURRENT) {
  962. set_charging_current_max = SIOP_INPUT_LIMIT_CURRENT;
  963. if (set_charging_current > SIOP_CHARGING_LIMIT_CURRENT)
  964. set_charging_current = SIOP_CHARGING_LIMIT_CURRENT;
  965. }
  966. }
  967. }
  968. }
  969. if (charger->pdata->full_check_type_2nd == SEC_BATTERY_FULLCHARGED_CHGPSY) {
  970. union power_supply_propval chg_mode;
  971. psy_do_property("battery", get, POWER_SUPPLY_PROP_CHARGE_NOW, chg_mode);
  972. if (chg_mode.intval == SEC_BATTERY_CHARGING_2ND) {
  973. max77804k_set_charger_state(charger, 0);
  974. max77804k_set_topoff_current(charger,
  975. charger->pdata->charging_current[
  976. charger->cable_type].full_check_current_2nd,
  977. (70 * 60));
  978. } else {
  979. max77804k_set_topoff_current(charger,
  980. charger->pdata->charging_current[
  981. charger->cable_type].full_check_current_1st,
  982. (70 * 60));
  983. }
  984. } else {
  985. max77804k_set_topoff_current(charger,
  986. charger->pdata->charging_current[
  987. val->intval].full_check_current_1st,
  988. charger->pdata->charging_current[
  989. val->intval].full_check_current_2nd);
  990. }
  991. max77804k_set_charger_state(charger, charger->is_charging);
  992. /* if battery full, only disable charging */
  993. if ((charger->status == POWER_SUPPLY_STATUS_CHARGING) ||
  994. (charger->status == POWER_SUPPLY_STATUS_DISCHARGING) ||
  995. (value.intval == POWER_SUPPLY_HEALTH_UNSPEC_FAILURE) ||
  996. (value.intval == POWER_SUPPLY_HEALTH_OVERHEATLIMIT)) {
  997. /* current setting */
  998. max77804k_set_charge_current(charger,
  999. set_charging_current);
  1000. /* if battery is removed, disable input current and reenable input current
  1001. * to enable buck always */
  1002. if (value.intval == POWER_SUPPLY_HEALTH_UNSPEC_FAILURE ||
  1003. value.intval == POWER_SUPPLY_HEALTH_OVERHEATLIMIT)
  1004. max77804k_set_input_current(charger, 0);
  1005. else
  1006. max77804k_set_input_current(charger,
  1007. set_charging_current_max);
  1008. }
  1009. break;
  1010. /* val->intval : input charging current */
  1011. case POWER_SUPPLY_PROP_CURRENT_MAX:
  1012. charger->charging_current_max = val->intval;
  1013. break;
  1014. /* val->intval : charging current */
  1015. case POWER_SUPPLY_PROP_CURRENT_AVG:
  1016. charger->charging_current = val->intval;
  1017. #if defined(CONFIG_BATTERY_SWELLING)
  1018. max77804k_set_charge_current(charger,
  1019. val->intval);
  1020. #endif
  1021. break;
  1022. case POWER_SUPPLY_PROP_CURRENT_NOW:
  1023. max77804k_set_charge_current(charger,
  1024. val->intval);
  1025. max77804k_set_input_current(charger,
  1026. val->intval);
  1027. break;
  1028. case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
  1029. charger->siop_level = val->intval;
  1030. if (charger->is_charging) {
  1031. /* decrease the charging current according to siop level */
  1032. int current_now =
  1033. charger->charging_current * val->intval / 100;
  1034. /* do forced set charging current */
  1035. if (current_now > 0 &&
  1036. current_now < usb_charging_current)
  1037. current_now = usb_charging_current;
  1038. if (charger->cable_type == POWER_SUPPLY_TYPE_MAINS) {
  1039. if (charger->siop_level < 100 ) {
  1040. set_charging_current_max = SIOP_INPUT_LIMIT_CURRENT;
  1041. } else {
  1042. set_charging_current_max =
  1043. charger->charging_current_max;
  1044. }
  1045. if (charger->siop_level < 100 &&
  1046. current_now > SIOP_CHARGING_LIMIT_CURRENT)
  1047. current_now = SIOP_CHARGING_LIMIT_CURRENT;
  1048. max77804k_set_input_current(charger,
  1049. set_charging_current_max);
  1050. } else if (charger->cable_type == POWER_SUPPLY_TYPE_WIRELESS) {
  1051. if (charger->siop_level < 100 ) {
  1052. set_charging_current_max = SIOP_WIRELESS_INPUT_LIMIT_CURRENT;
  1053. } else {
  1054. set_charging_current_max =
  1055. charger->charging_current_max;
  1056. }
  1057. if (charger->siop_level < 100 &&
  1058. current_now > SIOP_WIRELESS_CHARGING_LIMIT_CURRENT)
  1059. current_now = SIOP_WIRELESS_CHARGING_LIMIT_CURRENT;
  1060. max77804k_set_input_current(charger,
  1061. set_charging_current_max);
  1062. }
  1063. max77804k_set_charge_current(charger, current_now);
  1064. }
  1065. break;
  1066. #if defined(CONFIG_SAMSUNG_BATTERY_ENG_TEST)
  1067. case POWER_SUPPLY_PROP_CHARGE_TYPE:
  1068. {
  1069. u8 ctrl3, cnfg12;
  1070. if(val->intval == POWER_SUPPLY_TYPE_WIRELESS) {
  1071. cnfg12 = (0 << CHG_CNFG_12_CHGINSEL_SHIFT);
  1072. ctrl3 = (1 << CTRL3_JIGSET_SHIFT);
  1073. if (charger->cable_type == POWER_SUPPLY_TYPE_WIRELESS) {
  1074. #ifdef CONFIG_FORCE_FAST_CHARGE
  1075. /* Yank555 : Use Fast charge currents accroding to user settings */
  1076. if (force_fast_charge == FAST_CHARGE_FORCE_AC) {
  1077. /* We are in basic Fast Charge mode, so we substitute AC to WIRELESS levels */
  1078. charger->charging_current_max = WIRELESS_CHARGE_1000;
  1079. charger->charging_current = WIRELESS_CHARGE_1000 + 100;
  1080. } else if (force_fast_charge == FAST_CHARGE_FORCE_CUSTOM_MA) {
  1081. /* We are in custom current Fast Charge mode for WIRELESS */
  1082. charger->charging_current_max = wireless_charge_level;
  1083. charger->charging_current = min(wireless_charge_level+100, MAX_CHARGE_LEVEL);
  1084. }
  1085. #else
  1086. charger->charging_current_max = 650;
  1087. charger->charging_current = 750;
  1088. #endif // CONFIG_FORCE_FAST_CHARGE
  1089. max77804k_set_input_current(charger,
  1090. charger->charging_current_max);
  1091. max77804k_set_charge_current(charger, charger->charging_current);
  1092. }
  1093. }
  1094. else {
  1095. cnfg12 = (1 << CHG_CNFG_12_CHGINSEL_SHIFT);
  1096. ctrl3 = (0 << CTRL3_JIGSET_SHIFT);
  1097. }
  1098. max77804k_update_reg(charger->max77804k->muic, MAX77804K_MUIC_REG_CTRL3, ctrl3,
  1099. CTRL3_JIGSET_MASK);
  1100. max77804k_update_reg(charger->max77804k->i2c, MAX77804K_CHG_REG_CHG_CNFG_12, cnfg12,
  1101. CHG_CNFG_12_CHGINSEL_MASK);
  1102. pr_info("%s: ctrl3 : (0x%02x)\n", __func__, ctrl3);
  1103. pr_info("%s: set CNFG_12: 0x%x\n", __func__, cnfg12);
  1104. break;
  1105. }
  1106. #endif
  1107. #if defined(CONFIG_BATTERY_SWELLING)
  1108. case POWER_SUPPLY_PROP_VOLTAGE_MAX:
  1109. pr_info("%s: float voltage(%d)\n", __func__, val->intval);
  1110. reg_data = max77804k_get_float_voltage_data(val->intval);
  1111. max77804k_update_reg(charger->max77804k->i2c, MAX77804K_CHG_REG_CHG_CNFG_04,
  1112. (reg_data << CHG_CNFG_04_CHG_CV_PRM_SHIFT),
  1113. CHG_CNFG_04_CHG_CV_PRM_MASK);
  1114. max77804k_read_reg(charger->max77804k->i2c,
  1115. MAX77804K_CHG_REG_CHG_CNFG_04, &reg_data);
  1116. pr_info("%s: Float voltage set to : 0x%x\n", __func__, reg_data);
  1117. break;
  1118. #endif
  1119. default:
  1120. return -EINVAL;
  1121. }
  1122. return 0;
  1123. }
  1124. static u8 max77804k_get_float_voltage_data(
  1125. int float_voltage)
  1126. {
  1127. u8 data = 0x16;
  1128. if (float_voltage >= 4400)
  1129. data = 0x1f;
  1130. else if (float_voltage >= 4375)
  1131. data = 0x1e;
  1132. else if (float_voltage >= 4350)
  1133. data = 0x1d;
  1134. else if (float_voltage >= 4340)
  1135. data = 0x1c;
  1136. else
  1137. data = (float_voltage - 3650) / 25;
  1138. return data;
  1139. }
  1140. static void max77804k_charger_initialize(struct max77804k_charger_data *charger)
  1141. {
  1142. u8 reg_data;
  1143. pr_debug("%s\n", __func__);
  1144. /* unmasked: CHGIN_I, WCIN_I, BATP_I, BYP_I */
  1145. max77804k_write_reg(charger->max77804k->i2c,
  1146. MAX77804K_CHG_REG_CHG_INT_MASK, 0x9a);
  1147. /* unlock charger setting protect */
  1148. reg_data = (0x03 << 2);
  1149. max77804k_write_reg(charger->max77804k->i2c,
  1150. MAX77804K_CHG_REG_CHG_CNFG_06, reg_data);
  1151. /*
  1152. * fast charge timer disable
  1153. * restart threshold disable
  1154. * pre-qual charge enable(default)
  1155. */
  1156. reg_data = (0x0 << 0) | (0x03 << 4);
  1157. max77804k_write_reg(charger->max77804k->i2c,
  1158. MAX77804K_CHG_REG_CHG_CNFG_01, reg_data);
  1159. /*
  1160. * charge current 466mA(default)
  1161. * otg current limit 900mA
  1162. */
  1163. max77804k_read_reg(charger->max77804k->i2c,
  1164. MAX77804K_CHG_REG_CHG_CNFG_02, &reg_data);
  1165. reg_data |= (1 << 7);
  1166. max77804k_write_reg(charger->max77804k->i2c,
  1167. MAX77804K_CHG_REG_CHG_CNFG_02, reg_data);
  1168. /*
  1169. * top off current 100mA
  1170. * top off timer 40min
  1171. */
  1172. reg_data = (0x04 << 3);
  1173. max77804k_write_reg(charger->max77804k->i2c,
  1174. MAX77804K_CHG_REG_CHG_CNFG_03, reg_data);
  1175. /*
  1176. * cv voltage 4.2V or 4.35V
  1177. * MINVSYS 3.6V(default)
  1178. */
  1179. reg_data = max77804k_get_float_voltage_data(charger->pdata->chg_float_voltage);
  1180. max77804k_update_reg(charger->max77804k->i2c, MAX77804K_CHG_REG_CHG_CNFG_04,
  1181. (reg_data << CHG_CNFG_04_CHG_CV_PRM_SHIFT),
  1182. CHG_CNFG_04_CHG_CV_PRM_MASK);
  1183. max77804k_read_reg(charger->max77804k->i2c,
  1184. MAX77804K_CHG_REG_CHG_CNFG_04, &reg_data);
  1185. pr_info("%s: battery cv voltage 0x%x\n", __func__, reg_data);
  1186. }
  1187. static void sec_chg_isr_work(struct work_struct *work)
  1188. {
  1189. struct max77804k_charger_data *charger =
  1190. container_of(work, struct max77804k_charger_data, isr_work.work);
  1191. union power_supply_propval val;
  1192. if (charger->pdata->full_check_type ==
  1193. SEC_BATTERY_FULLCHARGED_CHGINT) {
  1194. val.intval = max77804k_get_charger_state(charger);
  1195. switch (val.intval) {
  1196. case POWER_SUPPLY_STATUS_DISCHARGING:
  1197. pr_err("%s: Interrupted but Discharging\n", __func__);
  1198. break;
  1199. case POWER_SUPPLY_STATUS_NOT_CHARGING:
  1200. pr_err("%s: Interrupted but NOT Charging\n", __func__);
  1201. break;
  1202. case POWER_SUPPLY_STATUS_FULL:
  1203. pr_info("%s: Interrupted by Full\n", __func__);
  1204. psy_do_property("battery", set,
  1205. POWER_SUPPLY_PROP_STATUS, val);
  1206. break;
  1207. case POWER_SUPPLY_STATUS_CHARGING:
  1208. pr_err("%s: Interrupted but Charging\n", __func__);
  1209. break;
  1210. case POWER_SUPPLY_STATUS_UNKNOWN:
  1211. default:
  1212. pr_err("%s: Invalid Charger Status\n", __func__);
  1213. break;
  1214. }
  1215. }
  1216. if (charger->pdata->ovp_uvlo_check_type ==
  1217. SEC_BATTERY_OVP_UVLO_CHGINT) {
  1218. val.intval = max77804k_get_health_state(charger);
  1219. switch (val.intval) {
  1220. case POWER_SUPPLY_HEALTH_OVERHEAT:
  1221. case POWER_SUPPLY_HEALTH_COLD:
  1222. pr_err("%s: Interrupted but Hot/Cold\n", __func__);
  1223. break;
  1224. case POWER_SUPPLY_HEALTH_DEAD:
  1225. pr_err("%s: Interrupted but Dead\n", __func__);
  1226. break;
  1227. case POWER_SUPPLY_HEALTH_OVERVOLTAGE:
  1228. case POWER_SUPPLY_HEALTH_UNDERVOLTAGE:
  1229. pr_info("%s: Interrupted by OVP/UVLO\n", __func__);
  1230. psy_do_property("battery", set,
  1231. POWER_SUPPLY_PROP_HEALTH, val);
  1232. break;
  1233. case POWER_SUPPLY_HEALTH_UNSPEC_FAILURE:
  1234. pr_err("%s: Interrupted but Unspec\n", __func__);
  1235. break;
  1236. case POWER_SUPPLY_HEALTH_GOOD:
  1237. pr_err("%s: Interrupted but Good\n", __func__);
  1238. break;
  1239. case POWER_SUPPLY_HEALTH_UNKNOWN:
  1240. default:
  1241. pr_err("%s: Invalid Charger Health\n", __func__);
  1242. break;
  1243. }
  1244. }
  1245. }
  1246. static irqreturn_t sec_chg_irq_thread(int irq, void *irq_data)
  1247. {
  1248. struct max77804k_charger_data *charger = irq_data;
  1249. pr_info("%s: Charger interrupt occured\n", __func__);
  1250. if ((charger->pdata->full_check_type ==
  1251. SEC_BATTERY_FULLCHARGED_CHGINT) ||
  1252. (charger->pdata->ovp_uvlo_check_type ==
  1253. SEC_BATTERY_OVP_UVLO_CHGINT))
  1254. schedule_delayed_work(&charger->isr_work, 0);
  1255. return IRQ_HANDLED;
  1256. }
  1257. #if defined(CONFIG_CHARGER_MAX77804K)
  1258. static void wpc_detect_work(struct work_struct *work)
  1259. {
  1260. struct max77804k_charger_data *chg_data = container_of(work,
  1261. struct max77804k_charger_data,
  1262. wpc_work.work);
  1263. int wc_w_state;
  1264. int retry_cnt;
  1265. union power_supply_propval value;
  1266. u8 reg_data;
  1267. pr_debug("%s\n", __func__);
  1268. max77804k_update_reg(chg_data->max77804k->i2c,
  1269. MAX77804K_CHG_REG_CHG_INT_MASK, 0, MAX77804K_WCIN_IM);
  1270. /* check and unlock */
  1271. check_charger_unlock_state(chg_data);
  1272. retry_cnt = 0;
  1273. do {
  1274. max77804k_read_reg(chg_data->max77804k->i2c,
  1275. MAX77804K_CHG_REG_CHG_INT_OK, &reg_data);
  1276. wc_w_state = (reg_data & MAX77804K_WCIN_OK)
  1277. >> MAX77804K_WCIN_OK_SHIFT;
  1278. msleep(50);
  1279. } while((retry_cnt++ < 2) && (wc_w_state == 0));
  1280. if ((chg_data->wc_w_state == 0) && (wc_w_state == 1)) {
  1281. value.intval = 1;
  1282. psy_do_property("wireless", set,
  1283. POWER_SUPPLY_PROP_ONLINE, value);
  1284. pr_info("%s: wpc activated, set V_INT as PN\n",
  1285. __func__);
  1286. } else if ((chg_data->wc_w_state == 1) && (wc_w_state == 0)) {
  1287. if (!chg_data->is_charging)
  1288. max77804k_set_charger_state(chg_data, true);
  1289. retry_cnt = 0;
  1290. do {
  1291. max77804k_read_reg(chg_data->max77804k->i2c,
  1292. MAX77804K_CHG_REG_CHG_DTLS_01, &reg_data);
  1293. reg_data = ((reg_data & MAX77804K_CHG_DTLS)
  1294. >> MAX77804K_CHG_DTLS_SHIFT);
  1295. msleep(50);
  1296. } while((retry_cnt++ < 2) && (reg_data == 0x8));
  1297. pr_info("%s: reg_data: 0x%x, charging: %d\n", __func__,
  1298. reg_data, chg_data->is_charging);
  1299. if (!chg_data->is_charging)
  1300. max77804k_set_charger_state(chg_data, false);
  1301. if ((reg_data != 0x08)
  1302. && (chg_data->cable_type == POWER_SUPPLY_TYPE_WIRELESS)) {
  1303. pr_info("%s: wpc uvlo, but charging\n", __func__);
  1304. queue_delayed_work(chg_data->wqueue, &chg_data->wpc_work,
  1305. msecs_to_jiffies(500));
  1306. return;
  1307. } else {
  1308. value.intval = 0;
  1309. psy_do_property("wireless", set,
  1310. POWER_SUPPLY_PROP_ONLINE, value);
  1311. pr_info("%s: wpc deactivated, set V_INT as PD\n",
  1312. __func__);
  1313. }
  1314. }
  1315. pr_info("%s: w(%d to %d)\n", __func__,
  1316. chg_data->wc_w_state, wc_w_state);
  1317. chg_data->wc_w_state = wc_w_state;
  1318. __pm_relax(&chg_data->wpc_ws);
  1319. }
  1320. static irqreturn_t wpc_charger_irq(int irq, void *data)
  1321. {
  1322. struct max77804k_charger_data *chg_data = data;
  1323. unsigned long delay;
  1324. max77804k_update_reg(chg_data->max77804k->i2c,
  1325. MAX77804K_CHG_REG_CHG_INT_MASK, MAX77804K_WCIN_IM, MAX77804K_WCIN_IM);
  1326. cancel_delayed_work_sync(&chg_data->wpc_work);
  1327. __pm_stay_awake(&chg_data->wpc_ws);
  1328. #ifdef CONFIG_SAMSUNG_BATTERY_FACTORY
  1329. delay = msecs_to_jiffies(0);
  1330. #else
  1331. if (chg_data->wc_w_state)
  1332. delay = msecs_to_jiffies(500);
  1333. else
  1334. delay = msecs_to_jiffies(20);
  1335. #endif
  1336. queue_delayed_work(chg_data->wqueue, &chg_data->wpc_work,
  1337. delay);
  1338. return IRQ_HANDLED;
  1339. }
  1340. #elif defined(CONFIG_WIRELESS_CHARGING)
  1341. static irqreturn_t wpc_charger_irq(int irq, void *data)
  1342. {
  1343. struct max77804k_charger_data *chg_data = data;
  1344. int wc_w_state;
  1345. union power_supply_propval value;
  1346. pr_info("%s: irq(%d)\n", __func__, irq);
  1347. /* check and unlock */
  1348. check_charger_unlock_state(chg_data);
  1349. wc_w_state = !gpio_get_value(chg_data->wc_w_gpio);
  1350. if ((chg_data->wc_w_state == 0) && (wc_w_state == 1)) {
  1351. value.intval = POWER_SUPPLY_TYPE_WIRELESS
  1352. <<ONLINE_TYPE_MAIN_SHIFT;
  1353. psy_do_property("battery", set,
  1354. POWER_SUPPLY_PROP_ONLINE, value);
  1355. pr_info("%s: wpc activated, set V_INT as PN\n",
  1356. __func__);
  1357. } else if ((chg_data->wc_w_state == 1) && (wc_w_state == 0)) {
  1358. value.intval =
  1359. POWER_SUPPLY_TYPE_BATTERY<<ONLINE_TYPE_MAIN_SHIFT;
  1360. psy_do_property("battery", set,
  1361. POWER_SUPPLY_PROP_ONLINE, value);
  1362. pr_info("%s: wpc deactivated, set V_INT as PD\n",
  1363. __func__);
  1364. }
  1365. pr_info("%s: w(%d to %d)\n", __func__,
  1366. chg_data->wc_w_state, wc_w_state);
  1367. chg_data->wc_w_state = wc_w_state;
  1368. return IRQ_HANDLED;
  1369. }
  1370. #endif
  1371. static irqreturn_t max77804k_bypass_irq(int irq, void *data)
  1372. {
  1373. struct max77804k_charger_data *chg_data = data;
  1374. u8 dtls_02;
  1375. u8 byp_dtls;
  1376. u8 chg_cnfg_00;
  1377. u8 vbus_state;
  1378. pr_info("%s: irq(%d)\n", __func__, irq);
  1379. /* check and unlock */
  1380. check_charger_unlock_state(chg_data);
  1381. max77804k_read_reg(chg_data->max77804k->i2c,
  1382. MAX77804K_CHG_REG_CHG_DTLS_02,
  1383. &dtls_02);
  1384. byp_dtls = ((dtls_02 & MAX77804K_BYP_DTLS) >>
  1385. MAX77804K_BYP_DTLS_SHIFT);
  1386. pr_info("%s: BYP_DTLS(0x%02x)\n", __func__, byp_dtls);
  1387. vbus_state = max77804k_get_vbus_state(chg_data);
  1388. if (byp_dtls & 0x1) {
  1389. pr_info("%s: bypass overcurrent limit\n", __func__);
  1390. #ifdef CONFIG_USB_HOST_NOTIFY
  1391. sec_otg_notify(HNOTIFY_OVERCURRENT);
  1392. #endif
  1393. /* disable the register values just related to OTG and
  1394. keep the values about the charging */
  1395. max77804k_read_reg(chg_data->max77804k->i2c,
  1396. MAX77804K_CHG_REG_CHG_CNFG_00, &chg_cnfg_00);
  1397. chg_cnfg_00 &= ~(CHG_CNFG_00_OTG_MASK
  1398. | CHG_CNFG_00_BOOST_MASK
  1399. | CHG_CNFG_00_DIS_MUIC_CTRL_MASK);
  1400. max77804k_write_reg(chg_data->max77804k->i2c,
  1401. MAX77804K_CHG_REG_CHG_CNFG_00,
  1402. chg_cnfg_00);
  1403. }
  1404. if (byp_dtls & 0x8) {
  1405. reduce_input_current(chg_data, REDUCE_CURRENT_STEP);
  1406. }
  1407. return IRQ_HANDLED;
  1408. }
  1409. static void max77804k_chgin_isr_work(struct work_struct *work)
  1410. {
  1411. struct max77804k_charger_data *charger = container_of(work,
  1412. struct max77804k_charger_data, chgin_work);
  1413. u8 chgin_dtls, chg_dtls, chg_cnfg_00;
  1414. u8 prev_chgin_dtls = 0xff;
  1415. int battery_health;
  1416. union power_supply_propval value;
  1417. int stable_count = 0;
  1418. __pm_stay_awake(&charger->chgin_ws);
  1419. max77804k_update_reg(charger->max77804k->i2c,
  1420. MAX77804K_CHG_REG_CHG_INT_MASK, MAX77804K_CHGIN_IM, MAX77804K_CHGIN_IM);
  1421. while (1) {
  1422. psy_do_property("battery", get,
  1423. POWER_SUPPLY_PROP_HEALTH, value);
  1424. battery_health = value.intval;
  1425. max77804k_read_reg(charger->max77804k->i2c,
  1426. MAX77804K_CHG_REG_CHG_DTLS_00,
  1427. &chgin_dtls);
  1428. chgin_dtls = ((chgin_dtls & MAX77804K_CHGIN_DTLS) >>
  1429. MAX77804K_CHGIN_DTLS_SHIFT);
  1430. max77804k_read_reg(charger->max77804k->i2c,
  1431. MAX77804K_CHG_REG_CHG_DTLS_01, &chg_dtls);
  1432. chg_dtls = ((chg_dtls & MAX77804K_CHG_DTLS) >>
  1433. MAX77804K_CHG_DTLS_SHIFT);
  1434. max77804k_read_reg(charger->max77804k->i2c,
  1435. MAX77804K_CHG_REG_CHG_CNFG_00, &chg_cnfg_00);
  1436. if (prev_chgin_dtls == chgin_dtls)
  1437. stable_count++;
  1438. else
  1439. stable_count = 0;
  1440. if (stable_count > 10) {
  1441. pr_info("%s: irq(%d), chgin(0x%x), chg_dtls(0x%x) prev 0x%x\n",
  1442. __func__, charger->irq_chgin,
  1443. chgin_dtls, chg_dtls, prev_chgin_dtls);
  1444. if (charger->is_charging) {
  1445. if ((chgin_dtls == 0x02) && \
  1446. (battery_health != POWER_SUPPLY_HEALTH_OVERVOLTAGE)) {
  1447. pr_info("%s: charger is over voltage\n",
  1448. __func__);
  1449. value.intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
  1450. psy_do_property("battery", set,
  1451. POWER_SUPPLY_PROP_HEALTH, value);
  1452. } else if (((chgin_dtls == 0x0) || (chgin_dtls == 0x01)) &&(chg_dtls & 0x08) && \
  1453. (chg_cnfg_00 & MAX77804K_MODE_BUCK) && \
  1454. (chg_cnfg_00 & MAX77804K_MODE_CHGR) && \
  1455. (battery_health != POWER_SUPPLY_HEALTH_UNDERVOLTAGE) && \
  1456. (charger->cable_type != POWER_SUPPLY_TYPE_WIRELESS)) {
  1457. pr_info("%s, vbus_state : 0x%d, chg_state : 0x%d\n", __func__, chgin_dtls, chg_dtls);
  1458. pr_info("%s: vBus is undervoltage\n", __func__);
  1459. value.intval = POWER_SUPPLY_HEALTH_UNDERVOLTAGE;
  1460. psy_do_property("battery", set,
  1461. POWER_SUPPLY_PROP_HEALTH, value);
  1462. }
  1463. } else {
  1464. if ((battery_health == \
  1465. POWER_SUPPLY_HEALTH_OVERVOLTAGE) &&
  1466. (chgin_dtls != 0x02)) {
  1467. pr_info("%s: vbus_state : 0x%d, chg_state : 0x%d\n", __func__, chgin_dtls, chg_dtls);
  1468. pr_info("%s: overvoltage->normal\n", __func__);
  1469. value.intval = POWER_SUPPLY_HEALTH_GOOD;
  1470. psy_do_property("battery", set,
  1471. POWER_SUPPLY_PROP_HEALTH, value);
  1472. } else if ((battery_health == \
  1473. POWER_SUPPLY_HEALTH_UNDERVOLTAGE) &&
  1474. !((chgin_dtls == 0x0) || (chgin_dtls == 0x01))){
  1475. pr_info("%s: vbus_state : 0x%d, chg_state : 0x%d\n", __func__, chgin_dtls, chg_dtls);
  1476. pr_info("%s: undervoltage->normal\n", __func__);
  1477. value.intval = POWER_SUPPLY_HEALTH_GOOD;
  1478. psy_do_property("battery", set,
  1479. POWER_SUPPLY_PROP_HEALTH, value);
  1480. max77804k_set_input_current(charger,
  1481. charger->charging_current_max);
  1482. }
  1483. }
  1484. break;
  1485. }
  1486. if (charger->is_charging) {
  1487. /* reduce only at CC MODE */
  1488. if (((chgin_dtls == 0x0) || (chgin_dtls == 0x01)) &&
  1489. (chg_dtls == 0x01) && (stable_count > 2))
  1490. reduce_input_current(charger, REDUCE_CURRENT_STEP);
  1491. }
  1492. prev_chgin_dtls = chgin_dtls;
  1493. msleep(100);
  1494. }
  1495. max77804k_update_reg(charger->max77804k->i2c,
  1496. MAX77804K_CHG_REG_CHG_INT_MASK, 0, MAX77804K_CHGIN_IM);
  1497. __pm_relax(&charger->chgin_ws);
  1498. }
  1499. static irqreturn_t max77804k_chgin_irq(int irq, void *data)
  1500. {
  1501. struct max77804k_charger_data *charger = data;
  1502. queue_work(charger->wqueue, &charger->chgin_work);
  1503. return IRQ_HANDLED;
  1504. }
  1505. static irqreturn_t max77804k_battery_irq(int irq, void *data)
  1506. {
  1507. struct max77804k_charger_data *charger = data;
  1508. union power_supply_propval value;
  1509. value.intval = max77804k_get_battery_present(charger);
  1510. pr_info("%s: battery present(%d)\n", __func__, value.intval);
  1511. psy_do_property("battery", set,
  1512. POWER_SUPPLY_PROP_PRESENT, value);
  1513. return IRQ_HANDLED;
  1514. }
  1515. /* register chgin/battery isr after sec_battery_probe */
  1516. static void max77804k_chgin_init_work(struct work_struct *work)
  1517. {
  1518. struct max77804k_charger_data *charger = container_of(work,
  1519. struct max77804k_charger_data,
  1520. chgin_init_work.work);
  1521. int ret;
  1522. pr_info("%s \n", __func__);
  1523. ret = request_threaded_irq(charger->irq_chgin, NULL,
  1524. max77804k_chgin_irq, 0, "chgin-irq", charger);
  1525. if (ret < 0) {
  1526. pr_err("%s: fail to request chgin IRQ: %d: %d\n",
  1527. __func__, charger->irq_chgin, ret);
  1528. }
  1529. if (charger->irq_battery > 0) {
  1530. ret = request_threaded_irq(charger->irq_battery, NULL,
  1531. max77804k_battery_irq, IRQF_TRIGGER_FALLING,
  1532. "battery-irq", charger);
  1533. if (ret < 0)
  1534. pr_err("%s: fail to request battery IRQ: %d: %d\n",
  1535. __func__, charger->irq_battery, ret);
  1536. }
  1537. }
  1538. #ifdef CONFIG_OF
  1539. static int sec_charger_read_u32_index_dt(const struct device_node *np,
  1540. const char *propname,
  1541. u32 index, u32 *out_value)
  1542. {
  1543. struct property *prop = of_find_property(np, propname, NULL);
  1544. u32 len = (index + 1) * sizeof(*out_value);
  1545. if (!prop)
  1546. return (-EINVAL);
  1547. if (!prop->value)
  1548. return (-ENODATA);
  1549. if (len > prop->length)
  1550. return (-EOVERFLOW);
  1551. *out_value = be32_to_cpup(((__be32 *)prop->value) + index);
  1552. return 0;
  1553. }
  1554. static int sec_charger_parse_dt(struct max77804k_charger_data *charger)
  1555. {
  1556. struct device_node *np = NULL;
  1557. sec_battery_platform_data_t *pdata = charger->pdata;
  1558. int ret = 0;
  1559. int i, len;
  1560. const u32 *p;
  1561. np = of_find_node_by_name(NULL, "battery");
  1562. if (np == NULL) {
  1563. pr_err("%s: np NULL\n", __func__);
  1564. goto err;
  1565. } else {
  1566. ret = of_property_read_u32(np, "battery,full_check_type",
  1567. &pdata->full_check_type);
  1568. ret = of_property_read_u32(np, "battery,full_check_type_2nd",
  1569. &pdata->full_check_type_2nd);
  1570. }
  1571. np = of_find_node_by_name(NULL, "charger");
  1572. if (np == NULL) {
  1573. pr_err("%s: np NULL\n", __func__);
  1574. goto err;
  1575. } else {
  1576. ret = of_property_read_u32(np, "battery,chg_float_voltage",
  1577. &pdata->chg_float_voltage);
  1578. ret = of_property_read_u32(np, "battery,ovp_uvlo_check_type",
  1579. &pdata->ovp_uvlo_check_type);
  1580. p = of_get_property(np, "battery,input_current_limit", &len);
  1581. len = len / sizeof(u32);
  1582. pdata->charging_current = kzalloc(sizeof(sec_charging_current_t) * len,
  1583. GFP_KERNEL);
  1584. for(i = 0; i < len; i++) {
  1585. ret = sec_charger_read_u32_index_dt(np,
  1586. "battery,input_current_limit", i,
  1587. &pdata->charging_current[i].input_current_limit);
  1588. ret = sec_charger_read_u32_index_dt(np,
  1589. "battery,fast_charging_current", i,
  1590. &pdata->charging_current[i].fast_charging_current);
  1591. ret = sec_charger_read_u32_index_dt(np,
  1592. "battery,full_check_current_1st", i,
  1593. &pdata->charging_current[i].full_check_current_1st);
  1594. ret = sec_charger_read_u32_index_dt(np,
  1595. "battery,full_check_current_2nd", i,
  1596. &pdata->charging_current[i].full_check_current_2nd);
  1597. }
  1598. np = of_find_node_by_name(NULL, "battery");
  1599. if (np == NULL) {
  1600. pr_err("%s : np NULL\n", __func__);
  1601. pdata->bat_irq_gpio = -1;
  1602. } else {
  1603. ret = of_get_named_gpio(np, "battery,ta_int", 0);
  1604. if (ret < 0) {
  1605. pr_info("%s use bat irq %d\n", __func__, ret);
  1606. /* temporally assign for check*/
  1607. /* Removed check for Rubens as interrupt was coming in power measurrment tests*/
  1608. #if !defined(CONFIG_SEC_RUBENS_PROJECT)
  1609. pdata->bat_irq_gpio = ret;
  1610. #endif
  1611. }
  1612. pdata->use_wireless_to_pogo = of_property_read_bool(np,
  1613. "battery,use_wireless_to_pogo");
  1614. }
  1615. }
  1616. err:
  1617. return ret;
  1618. }
  1619. #endif
  1620. static __devinit int max77804k_charger_probe(struct platform_device *pdev)
  1621. {
  1622. struct max77804k_dev *iodev = dev_get_drvdata(pdev->dev.parent);
  1623. struct max77804k_platform_data *pdata = dev_get_platdata(iodev->dev);
  1624. struct max77804k_charger_data *charger;
  1625. int ret = 0;
  1626. u8 reg_data;
  1627. pr_info("%s: MAX77804K Charger driver probe\n", __func__);
  1628. charger = kzalloc(sizeof(*charger), GFP_KERNEL);
  1629. if (!charger)
  1630. return -ENOMEM;
  1631. pdata->charger_data = kzalloc(sizeof(sec_battery_platform_data_t), GFP_KERNEL);
  1632. if (!pdata->charger_data) {
  1633. ret = -ENOMEM;
  1634. goto err_free;
  1635. }
  1636. charger->max77804k = iodev;
  1637. charger->pdata = pdata->charger_data;
  1638. charger->aicl_on = false;
  1639. charger->siop_level = 100;
  1640. #ifdef CONFIG_OF
  1641. if (sec_charger_parse_dt(charger))
  1642. dev_err(&pdev->dev,
  1643. "%s : Failed to get charger int\n", __func__);
  1644. #endif
  1645. platform_set_drvdata(pdev, charger);
  1646. charger->psy_chg.name = "sec-charger";
  1647. charger->psy_chg.type = POWER_SUPPLY_TYPE_UNKNOWN;
  1648. charger->psy_chg.get_property = sec_chg_get_property;
  1649. charger->psy_chg.set_property = sec_chg_set_property;
  1650. charger->psy_chg.properties = sec_charger_props;
  1651. charger->psy_chg.num_properties = ARRAY_SIZE(sec_charger_props);
  1652. mutex_init(&charger->ops_lock);
  1653. if (charger->pdata->chg_gpio_init) {
  1654. if (!charger->pdata->chg_gpio_init()) {
  1655. pr_err("%s: Failed to Initialize GPIO\n", __func__);
  1656. goto err_free;
  1657. }
  1658. }
  1659. max77804k_charger_initialize(charger);
  1660. if (max77804k_read_reg(charger->max77804k->i2c, MAX77804K_PMIC_REG_PMIC_ID1, &reg_data) < 0) {
  1661. pr_err("device not found on this channel (this is not an error)\n");
  1662. ret = -ENODEV;
  1663. goto err_free;
  1664. } else {
  1665. charger->pmic_ver = (reg_data & 0xf);
  1666. pr_info("%s: device found: ver.0x%x\n", __func__,
  1667. charger->pmic_ver);
  1668. }
  1669. if (charger->pmic_ver == 0x04) {
  1670. charger->input_curr_limit_step = 25;
  1671. charger->charging_curr_step= 400; // 0.1mA unit
  1672. } else {
  1673. charger->input_curr_limit_step = 20;
  1674. charger->charging_curr_step= 333; // 0.1mA unit
  1675. }
  1676. charger->wqueue =
  1677. create_singlethread_workqueue(dev_name(&pdev->dev));
  1678. if (!charger->wqueue) {
  1679. pr_err("%s: Fail to Create Workqueue\n", __func__);
  1680. goto err_free;
  1681. }
  1682. wakeup_source_init(&charger->chgin_ws, "charger-chgin");
  1683. INIT_WORK(&charger->chgin_work, max77804k_chgin_isr_work);
  1684. INIT_DELAYED_WORK(&charger->chgin_init_work, max77804k_chgin_init_work);
  1685. wakeup_source_init(&charger->recovery_ws, "charger-recovery");
  1686. INIT_DELAYED_WORK(&charger->recovery_work, max77804k_recovery_work);
  1687. wakeup_source_init(&charger->wpc_ws, "charger-wpc");
  1688. INIT_DELAYED_WORK(&charger->wpc_work, wpc_detect_work);
  1689. ret = power_supply_register(&pdev->dev, &charger->psy_chg);
  1690. if (ret) {
  1691. pr_err("%s: Failed to Register psy_chg\n", __func__);
  1692. goto err_power_supply_register;
  1693. }
  1694. if (charger->pdata->chg_irq) {
  1695. INIT_DELAYED_WORK_DEFERRABLE(
  1696. &charger->isr_work, sec_chg_isr_work);
  1697. ret = request_threaded_irq(charger->pdata->chg_irq,
  1698. NULL, sec_chg_irq_thread,
  1699. charger->pdata->chg_irq_attr,
  1700. "charger-irq", charger);
  1701. if (ret) {
  1702. pr_err("%s: Failed to Reqeust IRQ\n", __func__);
  1703. goto err_irq;
  1704. }
  1705. }
  1706. #if defined(CONFIG_CHARGER_MAX77804K)
  1707. charger->wc_w_irq = pdata->irq_base + MAX77804K_CHG_IRQ_WCIN_I;
  1708. ret = request_threaded_irq(charger->wc_w_irq,
  1709. NULL, wpc_charger_irq,
  1710. 0, "wpc-int", charger);
  1711. if (ret) {
  1712. pr_err("%s: Failed to Reqeust IRQ\n", __func__);
  1713. goto err_wc_irq;
  1714. }
  1715. max77804k_read_reg(charger->max77804k->i2c,
  1716. MAX77804K_CHG_REG_CHG_INT_OK, &reg_data);
  1717. charger->wc_w_state = (reg_data & MAX77804K_WCIN_OK)
  1718. >> MAX77804K_WCIN_OK_SHIFT;
  1719. #elif defined(CONFIG_WIRELESS_CHARGING)
  1720. charger->wc_w_gpio = pdata->wc_irq_gpio;
  1721. if (charger->wc_w_gpio) {
  1722. charger->wc_w_irq = gpio_to_irq(charger->wc_w_gpio);
  1723. ret = gpio_request(charger->wc_w_gpio, "wpc_charger-irq");
  1724. if (ret < 0) {
  1725. pr_err("%s: failed requesting gpio %d\n", __func__,
  1726. charger->wc_w_gpio);
  1727. goto err_wc_irq;
  1728. }
  1729. ret = request_threaded_irq(charger->wc_w_irq,
  1730. NULL, wpc_charger_irq,
  1731. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
  1732. IRQF_ONESHOT,
  1733. "wpc-int", charger);
  1734. if (ret) {
  1735. pr_err("%s: Failed to Reqeust IRQ\n", __func__);
  1736. goto err_wc_irq;
  1737. }
  1738. enable_irq_wake(charger->wc_w_irq);
  1739. charger->wc_w_state = !gpio_get_value(charger->wc_w_gpio);
  1740. }
  1741. #endif
  1742. charger->irq_chgin = pdata->irq_base + MAX77804K_CHG_IRQ_CHGIN_I;
  1743. if (charger->pdata->bat_irq_gpio < 0)
  1744. charger->irq_battery = pdata->irq_base + MAX77804K_CHG_IRQ_BATP_I;
  1745. /* enable chgin/battery irq after sec_battery_probe */
  1746. queue_delayed_work(charger->wqueue, &charger->chgin_init_work,
  1747. msecs_to_jiffies(3000));
  1748. charger->irq_bypass = pdata->irq_base + MAX77804K_CHG_IRQ_BYP_I;
  1749. ret = request_threaded_irq(charger->irq_bypass, NULL,
  1750. max77804k_bypass_irq, 0, "bypass-irq", charger);
  1751. if (ret < 0)
  1752. pr_err("%s: fail to request bypass IRQ: %d: %d\n",
  1753. __func__, charger->irq_bypass, ret);
  1754. return 0;
  1755. err_wc_irq:
  1756. free_irq(charger->pdata->chg_irq, NULL);
  1757. err_irq:
  1758. power_supply_unregister(&charger->psy_chg);
  1759. err_power_supply_register:
  1760. destroy_workqueue(charger->wqueue);
  1761. err_free:
  1762. kfree(charger);
  1763. return ret;
  1764. }
  1765. static int __devexit max77804k_charger_remove(struct platform_device *pdev)
  1766. {
  1767. struct max77804k_charger_data *charger =
  1768. platform_get_drvdata(pdev);
  1769. destroy_workqueue(charger->wqueue);
  1770. free_irq(charger->wc_w_irq, NULL);
  1771. free_irq(charger->pdata->chg_irq, NULL);
  1772. power_supply_unregister(&charger->psy_chg);
  1773. kfree(charger);
  1774. return 0;
  1775. }
  1776. #if defined CONFIG_PM
  1777. static int max77804k_charger_suspend(struct device *dev)
  1778. {
  1779. return 0;
  1780. }
  1781. static int max77804k_charger_resume(struct device *dev)
  1782. {
  1783. return 0;
  1784. }
  1785. #else
  1786. #define max77804k_charger_suspend NULL
  1787. #define max77804k_charger_resume NULL
  1788. #endif
  1789. static void max77804k_charger_shutdown(struct device *dev)
  1790. {
  1791. struct max77804k_charger_data *charger = dev_get_drvdata(dev);
  1792. u8 reg_data;
  1793. pr_info("%s: MAX77804K Charger driver shutdown\n", __func__);
  1794. if (!charger->max77804k->i2c) {
  1795. pr_err("%s: no max77804k i2c client\n", __func__);
  1796. return;
  1797. }
  1798. reg_data = 0x04;
  1799. max77804k_write_reg(charger->max77804k->i2c,
  1800. MAX77804K_CHG_REG_CHG_CNFG_00, reg_data);
  1801. reg_data = 0x19;
  1802. max77804k_write_reg(charger->max77804k->i2c,
  1803. MAX77804K_CHG_REG_CHG_CNFG_09, reg_data);
  1804. reg_data = 0x19;
  1805. max77804k_write_reg(charger->max77804k->i2c,
  1806. MAX77804K_CHG_REG_CHG_CNFG_10, reg_data);
  1807. reg_data = 0x64;
  1808. max77804k_write_reg(charger->max77804k->i2c,
  1809. MAX77804K_CHG_REG_CHG_CNFG_12, reg_data);
  1810. pr_info("func:%s \n", __func__);
  1811. }
  1812. static SIMPLE_DEV_PM_OPS(max77804k_charger_pm_ops, max77804k_charger_suspend,
  1813. max77804k_charger_resume);
  1814. static struct platform_driver max77804k_charger_driver = {
  1815. .driver = {
  1816. .name = "max77804k-charger",
  1817. .owner = THIS_MODULE,
  1818. .pm = &max77804k_charger_pm_ops,
  1819. .shutdown = max77804k_charger_shutdown,
  1820. },
  1821. .probe = max77804k_charger_probe,
  1822. .remove = __devexit_p(max77804k_charger_remove),
  1823. };
  1824. static int __init max77804k_charger_init(void)
  1825. {
  1826. pr_info("func:%s\n", __func__);
  1827. return platform_driver_register(&max77804k_charger_driver);
  1828. }
  1829. module_init(max77804k_charger_init);
  1830. static void __exit max77804k_charger_exit(void)
  1831. {
  1832. platform_driver_register(&max77804k_charger_driver);
  1833. }
  1834. module_exit(max77804k_charger_exit);
  1835. MODULE_DESCRIPTION("max77804k charger driver");
  1836. MODULE_AUTHOR("Samsung Electronics");
  1837. MODULE_LICENSE("GPL");