fg: cw2217 add ui_soc feature

we can modify ui_full to adjust  showing 100% limit
The default ui_full is 100, that is hard word.
config it to dts file,that can suit for muti-project

Change-Id: I2a44e28eb1bf1bc7dc66e589331a193fb9c174c7
Reviewed-on: https://gerrit.mot.com/2134308
SME-Granted: SME Approvals Granted
SLTApproved: Slta Waiver
Tested-by: Jira Key
Reviewed-by: Huosheng Liao <liaohs@motorola.com>
Submit-Approved: Jira Key
This commit is contained in:
liuyc20 2021-12-03 13:42:30 +08:00 • committed by Yuecai Liu
commit 4bfd0faa1a

View file

@ -124,6 +124,7 @@ struct cw_battery {
int ic_soc_h;
int ic_soc_l;
int ui_soc;
int raw_soc;
int temp;
long cw_current;
int cycle;
@ -131,6 +132,7 @@ struct cw_battery {
int fw_version;
int fcc_design;
int fcc;
int ui_full;
#if 0
long stb_current;
#endif
@ -328,7 +330,7 @@ static int cw_get_capacity(struct cw_battery *cw_bat)
{
int ret;
unsigned char reg_val[2] = { 0, 0 };
int ui_100 = CW_UI_FULL;
int ui_100 = cw_bat->ui_full;
int soc_h;
int soc_l;
int ui_soc;
@ -339,6 +341,7 @@ static int cw_get_capacity(struct cw_battery *cw_bat)
return ret;
soc_h = reg_val[0];
soc_l = reg_val[1];
cw_bat->raw_soc = soc_h;
ui_soc = ((soc_h * 256 + soc_l) * 100)/ (ui_100 * 256);
remainder = (((soc_h * 256 + soc_l) * 100 * 100) / (ui_100 * 256)) % 100;
if (ui_soc >= 100){
@ -516,8 +519,8 @@ static int cw_update_data(struct cw_battery *cw_bat)
ret += cw_get_current(cw_bat);
ret += cw_get_cycle_count(cw_bat);
ret += cw_get_soh(cw_bat);
cw_printk("vol = %d current = %ld cap = %d temp = %d age=%d\n",
cw_bat->voltage, cw_bat->cw_current, cw_bat->ui_soc, cw_bat->temp, cw_bat->soh);
cw_printk("vol = %d current = %ld cap = %d temp = %d raw_soc = %d age=%d\n",
cw_bat->voltage, cw_bat->cw_current, cw_bat->ui_soc, cw_bat->temp, cw_bat->raw_soc, cw_bat->soh);
return ret;
}
@ -534,8 +537,8 @@ static int cw_init_data(struct cw_battery *cw_bat)
ret += cw_get_cycle_count(cw_bat);
ret += cw_get_soh(cw_bat);
ret += cw_get_fw_version(cw_bat);
cw_printk("chip_id = %d vol = %d cur = %ld cap = %d temp = %d fw_version = %d\n",
cw_bat->chip_id, cw_bat->voltage, cw_bat->cw_current, cw_bat->ui_soc, cw_bat->temp, cw_bat->fw_version);
cw_printk("chip_id = %d vol = %d cur = %ld cap = %d raw_soc = %d temp = %d fw_version = %d\n",
cw_bat->chip_id, cw_bat->voltage, cw_bat->cw_current, cw_bat->ui_soc, cw_bat->raw_soc, cw_bat->temp, cw_bat->fw_version);
return ret;
}
@ -802,6 +805,12 @@ static int cw_parse_dts(struct cw_battery *cw_bat)
if (rc < 0)
cw_info("error,get fcc_design,exit \n");
rc = of_property_read_u32(batt_profile_node, "ui_full", &cw_bat->ui_full);
if (rc < 0) {
cw_bat->ui_full = CW_UI_FULL;
cw_info("dts get ui_full fail. use default ui_full=%d \n", CW_UI_FULL);
rc = 0;
}
return rc;
}