Loading drivers/power/supply/qcom/fg-alg.c +64 −2 Original line number Diff line number Diff line Loading @@ -164,13 +164,13 @@ void cycle_count_update(struct cycle_counter *counter, int batt_soc, } /** * get_cycle_count - * get_bucket_cycle_count - * @counter: Cycle counter object * * Returns the cycle counter for a SOC bucket. * */ int get_cycle_count(struct cycle_counter *counter) static int get_bucket_cycle_count(struct cycle_counter *counter) { int count; Loading @@ -186,6 +186,68 @@ int get_cycle_count(struct cycle_counter *counter) return count; } /** * get_cycle_counts - * @counter: Cycle counter object * @buf: Bucket cycle counts formatted in a string returned to the caller * * Get cycle count for all buckets in a string format */ int get_cycle_counts(struct cycle_counter *counter, const char **buf) { int i, rc, len = 0; for (i = 1; i <= BUCKET_COUNT; i++) { counter->id = i; rc = get_bucket_cycle_count(counter); if (rc < 0) { pr_err("Couldn't get cycle count rc=%d\n", rc); return rc; } if (sizeof(counter->str_buf) - len < 8) { pr_err("Invalid length %d\n", len); return -EINVAL; } len += snprintf(counter->str_buf+len, 8, "%d ", rc); } counter->str_buf[len] = '\0'; *buf = counter->str_buf; return 0; } /** * get_cycle_count - * @counter: Cycle counter object * @count: Average cycle count returned to the caller * * Get average cycle count for all buckets */ int get_cycle_count(struct cycle_counter *counter, int *count) { int i, rc, temp = 0; for (i = 1; i <= BUCKET_COUNT; i++) { counter->id = i; rc = get_bucket_cycle_count(counter); if (rc < 0) { pr_err("Couldn't get cycle count rc=%d\n", rc); return rc; } temp += rc; } /* * Normalize the counter across each bucket so that we can get * the overall charge cycle count. */ *count = temp / BUCKET_COUNT; return 0; } /** * cycle_count_init - * @counter: Cycle counter object Loading drivers/power/supply/qcom/fg-alg.h +3 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ struct cycle_counter { bool started[BUCKET_COUNT]; u16 count[BUCKET_COUNT]; u8 last_soc[BUCKET_COUNT]; char str_buf[BUCKET_COUNT * 8]; int id; int last_bucket; struct mutex lock; Loading Loading @@ -61,7 +62,8 @@ int restore_cycle_count(struct cycle_counter *counter); void clear_cycle_count(struct cycle_counter *counter); void cycle_count_update(struct cycle_counter *counter, int batt_soc, int charge_status, bool charge_done, bool input_present); int get_cycle_count(struct cycle_counter *counter); int get_cycle_count(struct cycle_counter *counter, int *count); int get_cycle_counts(struct cycle_counter *counter, const char **buf); int cycle_count_init(struct cycle_counter *counter); void cap_learning_abort(struct cap_learning *cl); void cap_learning_update(struct cap_learning *cl, int batt_temp, Loading drivers/power/supply/qcom/qg-core.h +0 −1 Original line number Diff line number Diff line Loading @@ -126,7 +126,6 @@ struct qpnp_qg { struct cap_learning *cl; /* charge counter */ struct cycle_counter *counter; char counter_buf[BUCKET_COUNT * 8]; }; enum ocv_type { Loading drivers/power/supply/qcom/qpnp-qg.c +7 −27 Original line number Diff line number Diff line Loading @@ -1195,32 +1195,6 @@ static int qg_get_battery_capacity(struct qpnp_qg *chip, int *soc) return 0; } static const char *qg_get_cycle_counts(struct qpnp_qg *chip) { int i, rc, len = 0; char *buf; buf = chip->counter_buf; for (i = 1; i <= BUCKET_COUNT; i++) { chip->counter->id = i; rc = get_cycle_count(chip->counter); if (rc < 0) { pr_err("Couldn't get cycle count rc=%d\n", rc); return NULL; } if (sizeof(chip->counter_buf) - len < 8) { pr_err("Invalid length %d\n", len); return NULL; } len += snprintf(buf+len, 8, "%d ", rc); } buf[len] = '\0'; return buf; } static int qg_psy_set_property(struct power_supply *psy, enum power_supply_property psp, const union power_supply_propval *pval) Loading Loading @@ -1326,7 +1300,12 @@ static int qg_psy_get_property(struct power_supply *psy, pval->intval = (int)temp; break; case POWER_SUPPLY_PROP_CYCLE_COUNTS: pval->strval = qg_get_cycle_counts(chip); rc = get_cycle_counts(chip->counter, &pval->strval); if (rc < 0) pval->strval = NULL; break; case POWER_SUPPLY_PROP_CYCLE_COUNT: rc = get_cycle_count(chip->counter, &pval->intval); break; default: pr_debug("Unsupported property %d\n", psp); Loading Loading @@ -1364,6 +1343,7 @@ static enum power_supply_property qg_psy_props[] = { POWER_SUPPLY_PROP_VOLTAGE_MAX, POWER_SUPPLY_PROP_BATT_FULL_CURRENT, POWER_SUPPLY_PROP_BATT_PROFILE_VERSION, POWER_SUPPLY_PROP_CYCLE_COUNT, POWER_SUPPLY_PROP_CYCLE_COUNTS, POWER_SUPPLY_PROP_CHARGE_FULL, POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, Loading Loading
drivers/power/supply/qcom/fg-alg.c +64 −2 Original line number Diff line number Diff line Loading @@ -164,13 +164,13 @@ void cycle_count_update(struct cycle_counter *counter, int batt_soc, } /** * get_cycle_count - * get_bucket_cycle_count - * @counter: Cycle counter object * * Returns the cycle counter for a SOC bucket. * */ int get_cycle_count(struct cycle_counter *counter) static int get_bucket_cycle_count(struct cycle_counter *counter) { int count; Loading @@ -186,6 +186,68 @@ int get_cycle_count(struct cycle_counter *counter) return count; } /** * get_cycle_counts - * @counter: Cycle counter object * @buf: Bucket cycle counts formatted in a string returned to the caller * * Get cycle count for all buckets in a string format */ int get_cycle_counts(struct cycle_counter *counter, const char **buf) { int i, rc, len = 0; for (i = 1; i <= BUCKET_COUNT; i++) { counter->id = i; rc = get_bucket_cycle_count(counter); if (rc < 0) { pr_err("Couldn't get cycle count rc=%d\n", rc); return rc; } if (sizeof(counter->str_buf) - len < 8) { pr_err("Invalid length %d\n", len); return -EINVAL; } len += snprintf(counter->str_buf+len, 8, "%d ", rc); } counter->str_buf[len] = '\0'; *buf = counter->str_buf; return 0; } /** * get_cycle_count - * @counter: Cycle counter object * @count: Average cycle count returned to the caller * * Get average cycle count for all buckets */ int get_cycle_count(struct cycle_counter *counter, int *count) { int i, rc, temp = 0; for (i = 1; i <= BUCKET_COUNT; i++) { counter->id = i; rc = get_bucket_cycle_count(counter); if (rc < 0) { pr_err("Couldn't get cycle count rc=%d\n", rc); return rc; } temp += rc; } /* * Normalize the counter across each bucket so that we can get * the overall charge cycle count. */ *count = temp / BUCKET_COUNT; return 0; } /** * cycle_count_init - * @counter: Cycle counter object Loading
drivers/power/supply/qcom/fg-alg.h +3 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ struct cycle_counter { bool started[BUCKET_COUNT]; u16 count[BUCKET_COUNT]; u8 last_soc[BUCKET_COUNT]; char str_buf[BUCKET_COUNT * 8]; int id; int last_bucket; struct mutex lock; Loading Loading @@ -61,7 +62,8 @@ int restore_cycle_count(struct cycle_counter *counter); void clear_cycle_count(struct cycle_counter *counter); void cycle_count_update(struct cycle_counter *counter, int batt_soc, int charge_status, bool charge_done, bool input_present); int get_cycle_count(struct cycle_counter *counter); int get_cycle_count(struct cycle_counter *counter, int *count); int get_cycle_counts(struct cycle_counter *counter, const char **buf); int cycle_count_init(struct cycle_counter *counter); void cap_learning_abort(struct cap_learning *cl); void cap_learning_update(struct cap_learning *cl, int batt_temp, Loading
drivers/power/supply/qcom/qg-core.h +0 −1 Original line number Diff line number Diff line Loading @@ -126,7 +126,6 @@ struct qpnp_qg { struct cap_learning *cl; /* charge counter */ struct cycle_counter *counter; char counter_buf[BUCKET_COUNT * 8]; }; enum ocv_type { Loading
drivers/power/supply/qcom/qpnp-qg.c +7 −27 Original line number Diff line number Diff line Loading @@ -1195,32 +1195,6 @@ static int qg_get_battery_capacity(struct qpnp_qg *chip, int *soc) return 0; } static const char *qg_get_cycle_counts(struct qpnp_qg *chip) { int i, rc, len = 0; char *buf; buf = chip->counter_buf; for (i = 1; i <= BUCKET_COUNT; i++) { chip->counter->id = i; rc = get_cycle_count(chip->counter); if (rc < 0) { pr_err("Couldn't get cycle count rc=%d\n", rc); return NULL; } if (sizeof(chip->counter_buf) - len < 8) { pr_err("Invalid length %d\n", len); return NULL; } len += snprintf(buf+len, 8, "%d ", rc); } buf[len] = '\0'; return buf; } static int qg_psy_set_property(struct power_supply *psy, enum power_supply_property psp, const union power_supply_propval *pval) Loading Loading @@ -1326,7 +1300,12 @@ static int qg_psy_get_property(struct power_supply *psy, pval->intval = (int)temp; break; case POWER_SUPPLY_PROP_CYCLE_COUNTS: pval->strval = qg_get_cycle_counts(chip); rc = get_cycle_counts(chip->counter, &pval->strval); if (rc < 0) pval->strval = NULL; break; case POWER_SUPPLY_PROP_CYCLE_COUNT: rc = get_cycle_count(chip->counter, &pval->intval); break; default: pr_debug("Unsupported property %d\n", psp); Loading Loading @@ -1364,6 +1343,7 @@ static enum power_supply_property qg_psy_props[] = { POWER_SUPPLY_PROP_VOLTAGE_MAX, POWER_SUPPLY_PROP_BATT_FULL_CURRENT, POWER_SUPPLY_PROP_BATT_PROFILE_VERSION, POWER_SUPPLY_PROP_CYCLE_COUNT, POWER_SUPPLY_PROP_CYCLE_COUNTS, POWER_SUPPLY_PROP_CHARGE_FULL, POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, Loading