charging_hw_ncp1854.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. #include <linux/types.h>
  2. #include <mt-plat/charging.h>
  3. #include <mt-plat/upmu_common.h>
  4. #include <linux/delay.h>
  5. #include <linux/reboot.h>
  6. #include <mt-plat/mt_boot.h>
  7. #include <mt-plat/battery_common.h>
  8. #include <mach/mt_charging.h>
  9. #include <mach/mt_pmic.h>
  10. #include "ncp1854.h"
  11. /* ============================================================ // */
  12. /* Define */
  13. /* ============================================================ // */
  14. #define STATUS_OK 0
  15. #define STATUS_FAIL 1
  16. #define STATUS_UNSUPPORTED -1
  17. #define GETARRAYNUM(array) (sizeof(array)/sizeof(array[0]))
  18. /* ============================================================ // */
  19. /* Global variable */
  20. /* ============================================================ // */
  21. #if defined(MTK_WIRELESS_CHARGER_SUPPORT)
  22. #define WIRELESS_CHARGER_EXIST_STATE 0
  23. #if defined(GPIO_PWR_AVAIL_WLC)
  24. unsigned int wireless_charger_gpio_number = GPIO_PWR_AVAIL_WLC;
  25. #else
  26. unsigned int wireless_charger_gpio_number = 0;
  27. #endif
  28. #endif
  29. /* As 82 platform mach/charging.h could not cover all voltage setting, just hardcoded below settings */
  30. const unsigned int VBAT_CV_VTH[] = {
  31. 3300000, 3325000, 3350000, 3375000,
  32. 3400000, 3425000, 3450000, 3475000,
  33. 3500000, 3525000, 3550000, 3575000,
  34. 3600000, 3625000, 3650000, 3675000,
  35. 3700000, 3725000, 3750000, 3775000,
  36. 3800000, 3825000, 3850000, 3875000,
  37. 3900000, 3925000, 3950000, 3975000,
  38. 4000000, 4025000, 4050000, 4075000,
  39. 4100000, 4125000, 4150000, 4175000,
  40. 4200000, 4225000, 4250000, 4275000,
  41. 4300000, 4325000, 4350000, 4375000,
  42. 4400000, 4425000, 4450000, 4475000,
  43. };
  44. /* hardcoded current define which defined in NCP1854 IC spec, as common define doesnot cover all define
  45. * double confirmed with onsemi register set in spec has issue,below is the correct setting */
  46. const unsigned int CS_VTH[] = {
  47. 45000, 50000, 60000, 70000,
  48. 80000, 90000, 100000, 110000,
  49. 120000, 130000, 140000, 150000,
  50. 160000, 170000, 180000, 190000
  51. };
  52. const unsigned int INPUT_CS_VTH[] = {
  53. CHARGE_CURRENT_100_00_MA, CHARGE_CURRENT_500_00_MA
  54. };
  55. const unsigned int INPUT_CS_VTH_TA[] = {
  56. CHARGE_CURRENT_600_00_MA, CHARGE_CURRENT_700_00_MA, CHARGE_CURRENT_800_00_MA,
  57. CHARGE_CURRENT_900_00_MA, CHARGE_CURRENT_1000_00_MA, CHARGE_CURRENT_1100_00_MA,
  58. CHARGE_CURRENT_1200_00_MA, CHARGE_CURRENT_1300_00_MA, CHARGE_CURRENT_1400_00_MA,
  59. CHARGE_CURRENT_1500_00_MA, CHARGE_CURRENT_1600_00_MA, 170000,
  60. 180000, 190000, 200000
  61. };
  62. const unsigned int VCDT_HV_VTH[] = {
  63. BATTERY_VOLT_04_200000_V, BATTERY_VOLT_04_250000_V, BATTERY_VOLT_04_300000_V,
  64. BATTERY_VOLT_04_350000_V,
  65. BATTERY_VOLT_04_400000_V, BATTERY_VOLT_04_450000_V, BATTERY_VOLT_04_500000_V,
  66. BATTERY_VOLT_04_550000_V,
  67. BATTERY_VOLT_04_600000_V, BATTERY_VOLT_06_000000_V, BATTERY_VOLT_06_500000_V,
  68. BATTERY_VOLT_07_000000_V,
  69. BATTERY_VOLT_07_500000_V, BATTERY_VOLT_08_500000_V, BATTERY_VOLT_09_500000_V,
  70. BATTERY_VOLT_10_500000_V
  71. };
  72. /* ============================================================ // */
  73. /* function prototype */
  74. /* ============================================================ // */
  75. /* ============================================================ // */
  76. /* extern variable */
  77. /* ============================================================ // */
  78. /* ============================================================ // */
  79. /* extern function */
  80. /* ============================================================ // */
  81. unsigned int current_high_flag = 0;
  82. /* ============================================================ // */
  83. unsigned int charging_value_to_parameter(const unsigned int *parameter, const unsigned int array_size,
  84. const unsigned int val)
  85. {
  86. unsigned int temp_param;
  87. if (val < array_size) {
  88. temp_param = parameter[val];
  89. } else {
  90. battery_log(BAT_LOG_CRTI, "Can't find the parameter \r\n");
  91. temp_param = parameter[0];
  92. }
  93. return temp_param;
  94. }
  95. unsigned int charging_parameter_to_value(const unsigned int *parameter, const unsigned int array_size,
  96. const unsigned int val)
  97. {
  98. unsigned int i;
  99. battery_log(BAT_LOG_FULL, "array_size = %d \r\n", array_size);
  100. for (i = 0; i < array_size; i++) {
  101. if (val == *(parameter + i))
  102. return i;
  103. }
  104. battery_log(BAT_LOG_CRTI, "NO register value match. val=%d\r\n", val);
  105. return 0;
  106. }
  107. static unsigned int bmt_find_closest_level(const unsigned int *pList, unsigned int number,
  108. unsigned int level)
  109. {
  110. unsigned int i, temp_param;
  111. unsigned int max_value_in_last_element;
  112. if (pList[0] < pList[1])
  113. max_value_in_last_element = KAL_TRUE;
  114. else
  115. max_value_in_last_element = KAL_FALSE;
  116. if (max_value_in_last_element == KAL_TRUE) {
  117. /* max value in the last element */
  118. for (i = (number - 1); i != 0; i--) {
  119. if (pList[i] <= level)
  120. return pList[i];
  121. }
  122. battery_log(BAT_LOG_CRTI, "Can't find closest level, small value first \r\n");
  123. temp_param = pList[0];
  124. } else {
  125. /* max value in the first element */
  126. for (i = 0; i < number; i++) {
  127. if (pList[i] <= level)
  128. return pList[i];
  129. }
  130. battery_log(BAT_LOG_CRTI, "Can't find closest level, large value first \r\n");
  131. temp_param = pList[number - 1];
  132. }
  133. return temp_param;
  134. }
  135. static unsigned int charging_hw_init(void *data)
  136. {
  137. unsigned int ncp1854_status;
  138. unsigned int status = STATUS_OK;
  139. pr_notice("[BATTERY:ncp1854] ChargerHwInit_ncp1854\n");
  140. ncp1854_status = ncp1854_get_chip_status();
  141. ncp1854_set_trans_en(0);
  142. ncp1854_set_tj_warn_opt(0x0); /* set at disabled, by MT6325 BATON */
  143. /* ncp1854_set_int_mask(0x0); //disable all interrupt */
  144. ncp1854_set_int_mask(0x1); /* enable all interrupt for boost mode status monitor */
  145. /* ncp1854_set_tchg_rst(0x1); //reset charge timer */
  146. ncp1854_set_chgto_dis(0x1); /* disable charge timer */
  147. /* WEAK WAIT, WEAK SAFE, WEAK CHARGE */
  148. if ((ncp1854_status == 0x8) || (ncp1854_status == 0x9) || (ncp1854_status == 0xA))
  149. ncp1854_set_ctrl_vbat(0x1C); /* VCHG = 4.0V */
  150. ncp1854_set_ieoc(0x6); /* cut off current = 250mA */
  151. ncp1854_set_iweak(0x3); /* weak charge current = 300mA */
  152. ncp1854_set_aicl_en(0x1); /* enable AICL as PT team suggest */
  153. ncp1854_set_iinset_pin_en(0x0); /* Input current limit and AICL control by I2C */
  154. ncp1854_set_ctrl_vfet(0x3); /* VFET = 3.4V */
  155. #if defined(MTK_WIRELESS_CHARGER_SUPPORT)
  156. if (wireless_charger_gpio_number != 0) {
  157. mt_set_gpio_mode(wireless_charger_gpio_number, 0); /* 0:GPIO mode */
  158. mt_set_gpio_dir(wireless_charger_gpio_number, 0); /* 0: input, 1: output */
  159. }
  160. #endif
  161. return status;
  162. }
  163. static unsigned int charging_dump_register(void *data)
  164. {
  165. unsigned int status = STATUS_OK;
  166. pr_notice("charging_dump_register\r\n");
  167. ncp1854_dump_register();
  168. return status;
  169. }
  170. static unsigned int charging_enable(void *data)
  171. {
  172. unsigned int status = STATUS_OK;
  173. unsigned int enable = *(unsigned int *) (data);
  174. if (KAL_TRUE == enable) {
  175. ncp1854_set_chg_en(0x1); /* charger enable */
  176. /* Set SPM = 1 */
  177. #ifdef GPIO_SWCHARGER_EN_PIN
  178. mt_set_gpio_mode(GPIO_SWCHARGER_EN_PIN, GPIO_MODE_00);
  179. mt_set_gpio_dir(GPIO_SWCHARGER_EN_PIN, GPIO_DIR_OUT);
  180. mt_set_gpio_out(GPIO_SWCHARGER_EN_PIN, GPIO_OUT_ONE);
  181. #endif
  182. } else {
  183. #if defined(CONFIG_USB_MTK_HDRC_HCD)
  184. if (mt_usb_is_device()) {
  185. #endif
  186. ncp1854_set_chg_en(0x0); /* charger disable */
  187. #if defined(CONFIG_USB_MTK_HDRC_HCD)
  188. }
  189. #endif
  190. }
  191. return status;
  192. }
  193. static unsigned int charging_set_cv_voltage(void *data)
  194. {
  195. unsigned int status = STATUS_OK;
  196. unsigned short register_value;
  197. unsigned int cv_value = *(unsigned int *) (data);
  198. unsigned int array_size;
  199. unsigned int set_chr_cv;
  200. if (batt_cust_data.high_battery_voltage_support)
  201. cv_value = BATTERY_VOLT_04_350000_V;
  202. /* use nearest value */
  203. array_size = GETARRAYNUM(VBAT_CV_VTH);
  204. set_chr_cv = bmt_find_closest_level(VBAT_CV_VTH, array_size, cv_value);
  205. register_value =
  206. charging_parameter_to_value(VBAT_CV_VTH, GETARRAYNUM(VBAT_CV_VTH), set_chr_cv);
  207. ncp1854_set_ctrl_vbat(register_value);
  208. return status;
  209. }
  210. static unsigned int charging_get_current(void *data)
  211. {
  212. unsigned int status = STATUS_OK;
  213. unsigned int array_size;
  214. unsigned char ret_val = 0;
  215. /* Get current level */
  216. /* ret_val = ncp1854_get_ichg(); */
  217. /* ncp1854_read_interface(NCP1854_CON15, &ret_val, CON15_ICHG_MASK, CON15_ICHG_SHIFT); */
  218. /* Parsing */
  219. /* ret_val = (ret_val*100) + 400; */
  220. array_size = GETARRAYNUM(CS_VTH);
  221. ret_val = ncp1854_get_ichg(); /* IINLIM */
  222. if (current_high_flag == 1)
  223. *(unsigned int *) data =
  224. charging_value_to_parameter(CS_VTH, array_size, ret_val) + 160000;
  225. else
  226. *(unsigned int *) data = charging_value_to_parameter(CS_VTH, array_size, ret_val);
  227. return status;
  228. }
  229. static unsigned int charging_set_current(void *data)
  230. {
  231. unsigned int status = STATUS_OK;
  232. unsigned int set_chr_current;
  233. unsigned int array_size;
  234. unsigned int register_value;
  235. unsigned int current_value = *(unsigned int *) data;
  236. array_size = GETARRAYNUM(CS_VTH);
  237. if (current_value <= 190000) {
  238. set_chr_current = bmt_find_closest_level(CS_VTH, array_size, current_value);
  239. register_value = charging_parameter_to_value(CS_VTH, array_size, set_chr_current);
  240. current_high_flag = 0x0;
  241. } else {
  242. set_chr_current =
  243. bmt_find_closest_level(CS_VTH, array_size, current_value - 160000);
  244. register_value = charging_parameter_to_value(CS_VTH, array_size, set_chr_current);
  245. current_high_flag = 0x1;
  246. }
  247. /* current set by SW and disable automatic charge current */
  248. /* ncp1854_set_aicl_en(0x0); //disable AICL */
  249. /* set which register first? mmz */
  250. ncp1854_set_ichg_high(current_high_flag);
  251. ncp1854_set_ichg(register_value);
  252. return status;
  253. }
  254. static unsigned int charging_set_input_current(void *data)
  255. {
  256. unsigned int status = STATUS_OK;
  257. unsigned int set_chr_current;
  258. unsigned int array_size;
  259. unsigned int register_value;
  260. unsigned int current_value = *(unsigned int *) data;
  261. if (current_value < 60000) {
  262. array_size = GETARRAYNUM(INPUT_CS_VTH);
  263. set_chr_current = bmt_find_closest_level(INPUT_CS_VTH, array_size, current_value);
  264. register_value =
  265. charging_parameter_to_value(INPUT_CS_VTH, array_size, set_chr_current);
  266. ncp1854_set_iinlim(register_value);
  267. ncp1854_set_iinlim_ta(0x0);
  268. } else {
  269. array_size = GETARRAYNUM(INPUT_CS_VTH_TA);
  270. set_chr_current =
  271. bmt_find_closest_level(INPUT_CS_VTH_TA, array_size, current_value);
  272. register_value =
  273. charging_parameter_to_value(INPUT_CS_VTH_TA, array_size, set_chr_current);
  274. ncp1854_set_iinlim_ta(register_value);
  275. }
  276. ncp1854_set_iinlim_en(0x1); /* enable input current limit */
  277. return status;
  278. }
  279. static unsigned int charging_get_charging_status(void *data)
  280. {
  281. unsigned int status = STATUS_OK;
  282. unsigned int ret_val;
  283. ret_val = ncp1854_get_chip_status();
  284. /* check whether chargeing DONE */
  285. if (ret_val == 0x6)
  286. *(unsigned int *) data = KAL_TRUE;
  287. else
  288. *(unsigned int *) data = KAL_FALSE;
  289. return status;
  290. }
  291. void kick_charger_wdt(void)
  292. {
  293. ncp1854_set_wdto_dis(0x0);
  294. }
  295. static unsigned int charging_reset_watch_dog_timer(void *data)
  296. {
  297. unsigned int status = STATUS_OK;
  298. battery_log(BAT_LOG_FULL, "charging_reset_watch_dog_timer\r\n");
  299. kick_charger_wdt();
  300. return status;
  301. }
  302. static unsigned int charging_set_hv_threshold(void *data)
  303. {
  304. unsigned int status = STATUS_OK;
  305. unsigned int set_hv_voltage;
  306. unsigned int array_size;
  307. unsigned short register_value;
  308. unsigned int voltage = *(unsigned int *) (data);
  309. array_size = GETARRAYNUM(VCDT_HV_VTH);
  310. set_hv_voltage = bmt_find_closest_level(VCDT_HV_VTH, array_size, voltage);
  311. register_value = charging_parameter_to_value(VCDT_HV_VTH, array_size, set_hv_voltage);
  312. pmic_set_register_value(PMIC_RG_VCDT_HV_VTH, register_value);
  313. return status;
  314. }
  315. static unsigned int charging_get_hv_status(void *data)
  316. {
  317. unsigned int status = STATUS_OK;
  318. #if defined(CONFIG_POWER_EXT) || defined(CONFIG_MTK_FPGA)
  319. *(kal_bool *) (data) = 0;
  320. pr_notice("[charging_get_hv_status] charger ok for bring up.\n");
  321. #else
  322. *(kal_bool *) (data) = pmic_get_register_value(PMIC_RGS_VCDT_HV_DET);
  323. #endif
  324. return status;
  325. }
  326. static unsigned int charging_get_battery_status(void *data)
  327. {
  328. unsigned int status = STATUS_OK;
  329. #if !defined(CONFIG_POWER_EXT)
  330. unsigned int val = 0;
  331. #endif
  332. #if defined(CONFIG_POWER_EXT) || defined(CONFIG_MTK_FPGA)
  333. *(kal_bool *) (data) = 0; /* battery exist */
  334. battery_log(BAT_LOG_CRTI, "[charging_get_battery_status] battery exist for bring up.\n");
  335. #else
  336. val = pmic_get_register_value(PMIC_BATON_TDET_EN);
  337. battery_log(BAT_LOG_FULL, "[charging_get_battery_status] BATON_TDET_EN = %d\n", val);
  338. if (val) {
  339. pmic_set_register_value(PMIC_BATON_TDET_EN, 1);
  340. pmic_set_register_value(PMIC_RG_BATON_EN, 1);
  341. *(kal_bool *) (data) = pmic_get_register_value(PMIC_RGS_BATON_UNDET);
  342. } else {
  343. *(kal_bool *) (data) = KAL_FALSE;
  344. }
  345. #endif
  346. return status;
  347. }
  348. static unsigned int charging_get_charger_det_status(void *data)
  349. {
  350. unsigned int status = STATUS_OK;
  351. unsigned int val = 0;
  352. #if defined(CONFIG_POWER_EXT) || defined(CONFIG_MTK_FPGA)
  353. val = 1;
  354. battery_log(BAT_LOG_CRTI, "[charging_get_charger_det_status] chr exist for fpga.\n");
  355. #else
  356. val = pmic_get_register_value(PMIC_RGS_CHRDET);
  357. #endif
  358. *(kal_bool *) (data) = val;
  359. return status;
  360. }
  361. static unsigned int charging_get_charger_type(void *data)
  362. {
  363. unsigned int status = STATUS_OK;
  364. #if defined(CONFIG_POWER_EXT) || defined(CONFIG_MTK_FPGA)
  365. *(CHARGER_TYPE *) (data) = STANDARD_HOST;
  366. #else
  367. *(CHARGER_TYPE *) (data) = hw_charging_get_charger_type();
  368. #endif
  369. return status;
  370. }
  371. static unsigned int charging_get_is_pcm_timer_trigger(void *data)
  372. {
  373. unsigned int status = STATUS_OK;
  374. /*
  375. #if defined(CONFIG_POWER_EXT) || defined(CONFIG_MTK_FPGA)
  376. *(kal_bool *) (data) = KAL_FALSE;
  377. #else
  378. if (slp_get_wake_reason() == WR_PCM_TIMER)
  379. *(kal_bool *) (data) = KAL_TRUE;
  380. else
  381. *(kal_bool *) (data) = KAL_FALSE;
  382. battery_log(BAT_LOG_CRTI, "slp_get_wake_reason=%d\n", slp_get_wake_reason());
  383. #endif
  384. */
  385. return status;
  386. }
  387. static unsigned int charging_set_platform_reset(void *data)
  388. {
  389. unsigned int status = STATUS_OK;
  390. #if defined(CONFIG_POWER_EXT) || defined(CONFIG_MTK_FPGA)
  391. #else
  392. battery_log(BAT_LOG_CRTI, "charging_set_platform_reset\n");
  393. kernel_restart("battery service reboot system");
  394. /* arch_reset(0,NULL); */
  395. #endif
  396. return status;
  397. }
  398. static unsigned int charging_get_platform_boot_mode(void *data)
  399. {
  400. unsigned int status = STATUS_OK;
  401. #if defined(CONFIG_POWER_EXT) || defined(CONFIG_MTK_FPGA)
  402. #else
  403. *(unsigned int *) (data) = get_boot_mode();
  404. battery_log(BAT_LOG_CRTI, "get_boot_mode=%d\n", get_boot_mode());
  405. #endif
  406. return status;
  407. }
  408. static unsigned int charging_set_power_off(void *data)
  409. {
  410. unsigned int status = STATUS_OK;
  411. #if defined(CONFIG_POWER_EXT) || defined(CONFIG_MTK_FPGA)
  412. #else
  413. battery_log(BAT_LOG_CRTI, "charging_set_power_off\n");
  414. kernel_power_off();
  415. #endif
  416. return status;
  417. }
  418. static unsigned int charging_get_power_source(void *data)
  419. {
  420. return STATUS_UNSUPPORTED;
  421. }
  422. static unsigned int charging_get_csdac_full_flag(void *data)
  423. {
  424. return STATUS_UNSUPPORTED;
  425. }
  426. static unsigned int charging_set_ta_current_pattern(void *data)
  427. {
  428. unsigned int status = STATUS_OK;
  429. unsigned int increase = *(unsigned int *) (data);
  430. #if defined(HIGH_BATTERY_VOLTAGE_SUPPORT)
  431. BATTERY_VOLTAGE_ENUM cv_voltage = BATTERY_VOLT_04_350000_V;
  432. #else
  433. BATTERY_VOLTAGE_ENUM cv_voltage = BATTERY_VOLT_04_200000_V;
  434. #endif
  435. charging_set_cv_voltage(&cv_voltage); /* Set CV */
  436. ncp1854_set_ichg(0x01); /* Set charging current 500ma */
  437. ncp1854_set_ichg_high(0x00);
  438. ncp1854_set_iinlim_ta(0x00);
  439. ncp1854_set_iinlim(0x01); /* set charging iinlim 500ma */
  440. ncp1854_set_iinlim_en(0x01); /* enable iinlim */
  441. ncp1854_set_chg_en(0x01); /* Enable Charging */
  442. /* ncp1854_dump_register(); */
  443. if (increase == KAL_TRUE) {
  444. ncp1854_set_iinlim(0x0); /* 100mA */
  445. msleep(85);
  446. ncp1854_set_iinlim(0x1); /* 500mA */
  447. battery_log(BAT_LOG_FULL, "mtk_ta_increase() on 1");
  448. msleep(85);
  449. ncp1854_set_iinlim(0x0); /* 100mA */
  450. battery_log(BAT_LOG_FULL, "mtk_ta_increase() off 1");
  451. msleep(85);
  452. ncp1854_set_iinlim(0x1); /* 500mA */
  453. battery_log(BAT_LOG_FULL, "mtk_ta_increase() on 2");
  454. msleep(85);
  455. ncp1854_set_iinlim(0x0); /* 100mA */
  456. battery_log(BAT_LOG_FULL, "mtk_ta_increase() off 2");
  457. msleep(85);
  458. ncp1854_set_iinlim(0x1); /* 500mA */
  459. battery_log(BAT_LOG_FULL, "mtk_ta_increase() on 3");
  460. msleep(281);
  461. ncp1854_set_iinlim(0x0); /* 100mA */
  462. battery_log(BAT_LOG_FULL, "mtk_ta_increase() off 3");
  463. msleep(85);
  464. ncp1854_set_iinlim(0x1); /* 500mA */
  465. battery_log(BAT_LOG_FULL, "mtk_ta_increase() on 4");
  466. msleep(281);
  467. ncp1854_set_iinlim(0x0); /* 100mA */
  468. battery_log(BAT_LOG_FULL, "mtk_ta_increase() off 4");
  469. msleep(85);
  470. ncp1854_set_iinlim(0x1); /* 500mA */
  471. battery_log(BAT_LOG_FULL, "mtk_ta_increase() on 5");
  472. msleep(281);
  473. ncp1854_set_iinlim(0x0); /* 100mA */
  474. battery_log(BAT_LOG_FULL, "mtk_ta_increase() off 5");
  475. msleep(85);
  476. ncp1854_set_iinlim(0x1); /* 500mA */
  477. battery_log(BAT_LOG_FULL, "mtk_ta_increase() on 6");
  478. msleep(485);
  479. ncp1854_set_iinlim(0x0); /* 100mA */
  480. battery_log(BAT_LOG_FULL, "mtk_ta_increase() off 6");
  481. msleep(50);
  482. battery_log(BAT_LOG_CRTI, "mtk_ta_increase() end\n");
  483. ncp1854_set_iinlim(0x1); /* 500mA */
  484. msleep(200);
  485. } else {
  486. ncp1854_set_iinlim(0x0); /* 100mA */
  487. msleep(85);
  488. ncp1854_set_iinlim(0x1); /* 500mA */
  489. battery_log(BAT_LOG_FULL, "mtk_ta_decrease() on 1");
  490. msleep(281);
  491. ncp1854_set_iinlim(0x0); /* 100mA */
  492. battery_log(BAT_LOG_FULL, "mtk_ta_decrease() off 1");
  493. msleep(85);
  494. ncp1854_set_iinlim(0x1); /* 500mA */
  495. battery_log(BAT_LOG_FULL, "mtk_ta_decrease() on 2");
  496. msleep(281);
  497. ncp1854_set_iinlim(0x0); /* 100mA */
  498. battery_log(BAT_LOG_FULL, "mtk_ta_decrease() off 2");
  499. msleep(85);
  500. ncp1854_set_iinlim(0x1); /* 500mA */
  501. battery_log(BAT_LOG_FULL, "mtk_ta_decrease() on 3");
  502. msleep(281);
  503. ncp1854_set_iinlim(0x0); /* 100mA */
  504. battery_log(BAT_LOG_FULL, "mtk_ta_decrease() off 3");
  505. msleep(85);
  506. ncp1854_set_iinlim(0x1); /* 500mA */
  507. battery_log(BAT_LOG_FULL, "mtk_ta_decrease() on 4");
  508. msleep(85);
  509. ncp1854_set_iinlim(0x0); /* 100mA */
  510. battery_log(BAT_LOG_FULL, "mtk_ta_decrease() off 4");
  511. msleep(85);
  512. ncp1854_set_iinlim(0x1); /* 500mA */
  513. battery_log(BAT_LOG_FULL, "mtk_ta_decrease() on 5");
  514. msleep(85);
  515. ncp1854_set_iinlim(0x0); /* 100mA */
  516. battery_log(BAT_LOG_FULL, "mtk_ta_decrease() off 5");
  517. msleep(85);
  518. ncp1854_set_iinlim(0x1); /* 500mA */
  519. battery_log(BAT_LOG_FULL, "mtk_ta_decrease() on 6");
  520. msleep(485);
  521. ncp1854_set_iinlim(0x0); /* 100mA */
  522. battery_log(BAT_LOG_FULL, "mtk_ta_decrease() off 6");
  523. msleep(50);
  524. battery_log(BAT_LOG_CRTI, "mtk_ta_decrease() end\n");
  525. ncp1854_set_iinlim(0x1); /* 500mA */
  526. }
  527. return status;
  528. }
  529. static unsigned int charging_set_error_state(void *data)
  530. {
  531. return STATUS_UNSUPPORTED;
  532. }
  533. static unsigned int charging_diso_init(void *data)
  534. {
  535. return STATUS_UNSUPPORTED;
  536. }
  537. static unsigned int charging_get_diso_state(void *data)
  538. {
  539. return STATUS_UNSUPPORTED;
  540. }
  541. static unsigned int (*const charging_func[CHARGING_CMD_NUMBER]) (void *data) = {
  542. charging_hw_init,
  543. charging_dump_register,
  544. charging_enable,
  545. charging_set_cv_voltage,
  546. charging_get_current,
  547. charging_set_current,
  548. charging_set_input_current,
  549. charging_get_charging_status,
  550. charging_reset_watch_dog_timer,
  551. charging_set_hv_threshold,
  552. charging_get_hv_status,
  553. charging_get_battery_status,
  554. charging_get_charger_det_status,
  555. charging_get_charger_type,
  556. charging_get_is_pcm_timer_trigger,
  557. charging_set_platform_reset,
  558. charging_get_platform_boot_mode,
  559. charging_set_power_off,
  560. charging_get_power_source,
  561. charging_get_csdac_full_flag,
  562. charging_set_ta_current_pattern,
  563. charging_set_error_state,
  564. charging_diso_init,
  565. charging_get_diso_state
  566. };
  567. /*
  568. * FUNCTION
  569. * Internal_chr_control_handler
  570. *
  571. * DESCRIPTION
  572. * This function is called to set the charger hw
  573. *
  574. * CALLS
  575. *
  576. * PARAMETERS
  577. * None
  578. *
  579. * RETURNS
  580. *
  581. *
  582. * GLOBALS AFFECTED
  583. * None
  584. */
  585. signed int chr_control_interface(CHARGING_CTRL_CMD cmd, void *data)
  586. {
  587. signed int status;
  588. if (cmd < CHARGING_CMD_NUMBER)
  589. status = charging_func[cmd] (data);
  590. else
  591. return STATUS_UNSUPPORTED;
  592. return status;
  593. }