From 092b09553758235b111d02178dba891b6c6fd3b7 Mon Sep 17 00:00:00 2001 From: Subbaraman Narayanamurthy Date: Tue, 8 Aug 2017 19:28:37 -0700 Subject: [PATCH] power: qpnp-fg-gen3: adjust ki coefficient for full soc dynamically In certain conditions, after the battery SOC reaches 100%, SOC is not getting updated during discharging. Based on the hardware recommendation, adjust the Ki coefficient for full SOC so that SOC can be updated faster during discharging. While at it, remove prev_charge_status variable which is not used really. CRs-Fixed: 2089555 Change-Id: I54b7d86529c21c016ab777053895ccda9c7a2b35 Signed-off-by: Subbaraman Narayanamurthy --- .../bindings/power/supply/qcom/qpnp-fg-gen3.txt | 7 +++++++ drivers/power/supply/qcom/fg-core.h | 2 +- drivers/power/supply/qcom/qpnp-fg-gen3.c | 10 +++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/power/supply/qcom/qpnp-fg-gen3.txt b/Documentation/devicetree/bindings/power/supply/qcom/qpnp-fg-gen3.txt index dc04942d6792..4207b1f0615a 100644 --- a/Documentation/devicetree/bindings/power/supply/qcom/qpnp-fg-gen3.txt +++ b/Documentation/devicetree/bindings/power/supply/qcom/qpnp-fg-gen3.txt @@ -309,6 +309,13 @@ First Level Node - FG Gen3 device is specified to make it fully functional. Value has no unit. Allowed range is 0 to 62200 in micro units. +- qcom,ki-coeff-full-dischg + Usage: optional + Value type: + Definition: Ki coefficient full SOC value that will be applied during + discharging. If not specified, a value of 0 will be set. + Allowed range is from 245 to 62256. + - qcom,fg-rconn-mohms Usage: optional Value type: diff --git a/drivers/power/supply/qcom/fg-core.h b/drivers/power/supply/qcom/fg-core.h index 16441d6e09e4..232dd4ec8606 100644 --- a/drivers/power/supply/qcom/fg-core.h +++ b/drivers/power/supply/qcom/fg-core.h @@ -273,6 +273,7 @@ struct fg_dt_props { int slope_limit_temp; int esr_pulse_thresh_ma; int esr_meas_curr_ma; + int ki_coeff_full_soc_dischg; int jeita_thresholds[NUM_JEITA_LEVELS]; int ki_coeff_soc[KI_COEFF_SOC_LEVELS]; int ki_coeff_med_dischg[KI_COEFF_SOC_LEVELS]; @@ -410,7 +411,6 @@ struct fg_chip { int batt_id_ohms; int ki_coeff_full_soc; int charge_status; - int prev_charge_status; int charge_done; int charge_type; int online_status; diff --git a/drivers/power/supply/qcom/qpnp-fg-gen3.c b/drivers/power/supply/qcom/qpnp-fg-gen3.c index 4788053115e1..8afd4b274335 100644 --- a/drivers/power/supply/qcom/qpnp-fg-gen3.c +++ b/drivers/power/supply/qcom/qpnp-fg-gen3.c @@ -1631,6 +1631,8 @@ static int fg_adjust_ki_coeff_full_soc(struct fg_chip *chip, int batt_temp) if (batt_temp < 0) ki_coeff_full_soc = 0; + else if (chip->charge_status == POWER_SUPPLY_STATUS_DISCHARGING) + ki_coeff_full_soc = chip->dt.ki_coeff_full_soc_dischg; else ki_coeff_full_soc = KI_COEFF_FULL_SOC_DEFAULT; @@ -2507,7 +2509,6 @@ static void status_change_work(struct work_struct *work) goto out; } - chip->prev_charge_status = chip->charge_status; chip->charge_status = prop.intval; rc = power_supply_get_property(chip->batt_psy, POWER_SUPPLY_PROP_CHARGE_TYPE, &prop); @@ -4476,7 +4477,11 @@ static int fg_parse_slope_limit_coefficients(struct fg_chip *chip) static int fg_parse_ki_coefficients(struct fg_chip *chip) { struct device_node *node = chip->dev->of_node; - int rc, i; + int rc, i, temp; + + rc = of_property_read_u32(node, "qcom,ki-coeff-full-dischg", &temp); + if (!rc) + chip->dt.ki_coeff_full_soc_dischg = temp; rc = fg_parse_dt_property_u32_array(node, "qcom,ki-coeff-soc-dischg", chip->dt.ki_coeff_soc, KI_COEFF_SOC_LEVELS); @@ -4929,7 +4934,6 @@ static int fg_gen3_probe(struct platform_device *pdev) chip->debug_mask = &fg_gen3_debug_mask; chip->irqs = fg_irqs; chip->charge_status = -EINVAL; - chip->prev_charge_status = -EINVAL; chip->ki_coeff_full_soc = -EINVAL; chip->online_status = -EINVAL; chip->regmap = dev_get_regmap(chip->dev->parent, NULL);