Loading drivers/power/supply/qcom/qg-core.h +6 −1 Original line number Diff line number Diff line /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (c) 2018 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. */ #ifndef __QG_CORE_H__ Loading Loading @@ -58,6 +58,7 @@ struct qg_dt { bool esr_disable; bool esr_discharge_enable; bool qg_ext_sense; bool use_s7_ocv; }; struct qg_esr_data { Loading Loading @@ -101,6 +102,7 @@ struct qpnp_qg { struct qg_user_data udata; struct power_supply *batt_psy; struct power_supply *usb_psy; struct power_supply *dc_psy; struct power_supply *parallel_psy; struct qg_esr_data esr_data[QG_MAX_ESR_COUNT]; Loading @@ -115,7 +117,9 @@ struct qpnp_qg { bool charge_done; bool parallel_enabled; bool usb_present; bool dc_present; bool charge_full; bool force_soc; int charge_status; int charge_type; int chg_iterm_ma; Loading Loading @@ -205,6 +209,7 @@ enum qg_wa_flags { QG_VBAT_LOW_WA = BIT(0), QG_RECHARGE_SOC_WA = BIT(1), QG_CLK_ADJUST_WA = BIT(2), QG_PON_OCV_WA = BIT(3), }; Loading drivers/power/supply/qcom/qg-reg.h +5 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,9 @@ #define QG_INT_LATCHED_STS_REG 0x18 #define FIFO_UPDATE_DONE_INT_LAT_STS_BIT BIT(3) #define QG_STATE_TRIG_CMD_REG 0x40 #define S7_PON_OCV_START BIT(3) #define QG_DATA_CTL1_REG 0x41 #define MASTER_HOLD_OR_CLR_BIT BIT(0) Loading Loading @@ -86,6 +89,8 @@ #define QG_POST_ESR_V_DATA0_REG 0x7C #define QG_POST_ESR_I_DATA0_REG 0x7E #define QG_S2_NORMAL_AVG_V_DATA0_REG 0x80 #define QG_V_ACCUM_DATA0_RT_REG 0x88 #define QG_I_ACCUM_DATA0_RT_REG 0x8B #define QG_ACCUM_CNT_RT_REG 0x8E Loading drivers/power/supply/qcom/qg-soc.c +7 −7 Original line number Diff line number Diff line // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2018 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. */ #define pr_fmt(fmt) "QG-K: %s: " fmt, __func__ Loading Loading @@ -175,8 +175,8 @@ static bool is_scaling_required(struct qpnp_qg *chip) return false; if (chip->catch_up_soc > chip->msoc && !is_usb_present(chip)) /* USB is not present and SOC has increased */ if (chip->catch_up_soc > chip->msoc && !is_input_present(chip)) /* input is not present and SOC has increased */ return false; return true; Loading Loading @@ -210,11 +210,11 @@ static bool maint_soc_timeout(struct qpnp_qg *chip) static void update_msoc(struct qpnp_qg *chip) { int rc = 0, sdam_soc, batt_temp = 0, batt_soc_32bit = 0; bool usb_present = is_usb_present(chip); bool input_present = is_input_present(chip); if (chip->catch_up_soc > chip->msoc) { /* SOC increased */ if (usb_present) /* Increment if USB is present */ if (input_present) /* Increment if input is present */ chip->msoc += chip->dt.delta_soc; } else if (chip->catch_up_soc < chip->msoc) { /* SOC dropped */ Loading Loading @@ -254,14 +254,14 @@ static void update_msoc(struct qpnp_qg *chip) QG_SOC_FULL); cap_learning_update(chip->cl, batt_temp, batt_soc_32bit, chip->charge_status, chip->charge_done, usb_present, false); input_present, false); } } cycle_count_update(chip->counter, DIV_ROUND_CLOSEST(chip->msoc * 255, 100), chip->charge_status, chip->charge_done, usb_present); input_present); qg_dbg(chip, QG_DEBUG_SOC, "SOC scale: Update maint_soc=%d msoc=%d catch_up_soc=%d delta_soc=%d\n", Loading drivers/power/supply/qcom/qg-util.c +46 −1 Original line number Diff line number Diff line // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2018 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. */ #include <linux/alarmtimer.h> Loading Loading @@ -268,6 +268,18 @@ static bool is_usb_available(struct qpnp_qg *chip) return true; } static bool is_dc_available(struct qpnp_qg *chip) { if (chip->dc_psy) return true; chip->dc_psy = power_supply_get_by_name("dc"); if (!chip->dc_psy) return false; return true; } bool is_usb_present(struct qpnp_qg *chip) { union power_supply_propval pval = {0, }; Loading @@ -279,6 +291,22 @@ bool is_usb_present(struct qpnp_qg *chip) return pval.intval ? true : false; } bool is_dc_present(struct qpnp_qg *chip) { union power_supply_propval pval = {0, }; if (is_dc_available(chip)) power_supply_get_property(chip->dc_psy, POWER_SUPPLY_PROP_PRESENT, &pval); return pval.intval ? true : false; } bool is_input_present(struct qpnp_qg *chip) { return is_usb_present(chip) || is_dc_present(chip); } static bool is_parallel_available(struct qpnp_qg *chip) { if (chip->parallel_psy) Loading Loading @@ -392,3 +420,20 @@ int qg_get_battery_voltage(struct qpnp_qg *chip, int *vbat_uv) return rc; } int qg_get_vbat_avg(struct qpnp_qg *chip, int *vbat_uv) { int rc = 0; u64 last_vbat = 0; rc = qg_read(chip, chip->qg_base + QG_S2_NORMAL_AVG_V_DATA0_REG, (u8 *)&last_vbat, 2); if (rc < 0) { pr_err("Failed to read S2_NORMAL_AVG_V reg, rc=%d\n", rc); return rc; } *vbat_uv = V_RAW_TO_UV(last_vbat); return 0; } drivers/power/supply/qcom/qg-util.h +4 −1 Original line number Diff line number Diff line /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (c) 2018 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. */ #ifndef __QG_UTIL_H__ Loading @@ -16,11 +16,14 @@ int get_sample_interval(struct qpnp_qg *chip, u32 *sample_interval); int get_fifo_done_time(struct qpnp_qg *chip, bool rt, int *time_ms); int get_rtc_time(unsigned long *rtc_time); bool is_usb_present(struct qpnp_qg *chip); bool is_dc_present(struct qpnp_qg *chip); bool is_input_present(struct qpnp_qg *chip); bool is_parallel_enabled(struct qpnp_qg *chip); int qg_write_monotonic_soc(struct qpnp_qg *chip, int msoc); int qg_get_battery_temp(struct qpnp_qg *chip, int *batt_temp); int qg_get_battery_current(struct qpnp_qg *chip, int *ibat_ua); int qg_get_battery_voltage(struct qpnp_qg *chip, int *vbat_uv); int qg_get_vbat_avg(struct qpnp_qg *chip, int *vbat_uv); s64 qg_iraw_to_ua(struct qpnp_qg *chip, int iraw); #endif Loading
drivers/power/supply/qcom/qg-core.h +6 −1 Original line number Diff line number Diff line /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (c) 2018 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. */ #ifndef __QG_CORE_H__ Loading Loading @@ -58,6 +58,7 @@ struct qg_dt { bool esr_disable; bool esr_discharge_enable; bool qg_ext_sense; bool use_s7_ocv; }; struct qg_esr_data { Loading Loading @@ -101,6 +102,7 @@ struct qpnp_qg { struct qg_user_data udata; struct power_supply *batt_psy; struct power_supply *usb_psy; struct power_supply *dc_psy; struct power_supply *parallel_psy; struct qg_esr_data esr_data[QG_MAX_ESR_COUNT]; Loading @@ -115,7 +117,9 @@ struct qpnp_qg { bool charge_done; bool parallel_enabled; bool usb_present; bool dc_present; bool charge_full; bool force_soc; int charge_status; int charge_type; int chg_iterm_ma; Loading Loading @@ -205,6 +209,7 @@ enum qg_wa_flags { QG_VBAT_LOW_WA = BIT(0), QG_RECHARGE_SOC_WA = BIT(1), QG_CLK_ADJUST_WA = BIT(2), QG_PON_OCV_WA = BIT(3), }; Loading
drivers/power/supply/qcom/qg-reg.h +5 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,9 @@ #define QG_INT_LATCHED_STS_REG 0x18 #define FIFO_UPDATE_DONE_INT_LAT_STS_BIT BIT(3) #define QG_STATE_TRIG_CMD_REG 0x40 #define S7_PON_OCV_START BIT(3) #define QG_DATA_CTL1_REG 0x41 #define MASTER_HOLD_OR_CLR_BIT BIT(0) Loading Loading @@ -86,6 +89,8 @@ #define QG_POST_ESR_V_DATA0_REG 0x7C #define QG_POST_ESR_I_DATA0_REG 0x7E #define QG_S2_NORMAL_AVG_V_DATA0_REG 0x80 #define QG_V_ACCUM_DATA0_RT_REG 0x88 #define QG_I_ACCUM_DATA0_RT_REG 0x8B #define QG_ACCUM_CNT_RT_REG 0x8E Loading
drivers/power/supply/qcom/qg-soc.c +7 −7 Original line number Diff line number Diff line // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2018 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. */ #define pr_fmt(fmt) "QG-K: %s: " fmt, __func__ Loading Loading @@ -175,8 +175,8 @@ static bool is_scaling_required(struct qpnp_qg *chip) return false; if (chip->catch_up_soc > chip->msoc && !is_usb_present(chip)) /* USB is not present and SOC has increased */ if (chip->catch_up_soc > chip->msoc && !is_input_present(chip)) /* input is not present and SOC has increased */ return false; return true; Loading Loading @@ -210,11 +210,11 @@ static bool maint_soc_timeout(struct qpnp_qg *chip) static void update_msoc(struct qpnp_qg *chip) { int rc = 0, sdam_soc, batt_temp = 0, batt_soc_32bit = 0; bool usb_present = is_usb_present(chip); bool input_present = is_input_present(chip); if (chip->catch_up_soc > chip->msoc) { /* SOC increased */ if (usb_present) /* Increment if USB is present */ if (input_present) /* Increment if input is present */ chip->msoc += chip->dt.delta_soc; } else if (chip->catch_up_soc < chip->msoc) { /* SOC dropped */ Loading Loading @@ -254,14 +254,14 @@ static void update_msoc(struct qpnp_qg *chip) QG_SOC_FULL); cap_learning_update(chip->cl, batt_temp, batt_soc_32bit, chip->charge_status, chip->charge_done, usb_present, false); input_present, false); } } cycle_count_update(chip->counter, DIV_ROUND_CLOSEST(chip->msoc * 255, 100), chip->charge_status, chip->charge_done, usb_present); input_present); qg_dbg(chip, QG_DEBUG_SOC, "SOC scale: Update maint_soc=%d msoc=%d catch_up_soc=%d delta_soc=%d\n", Loading
drivers/power/supply/qcom/qg-util.c +46 −1 Original line number Diff line number Diff line // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2018 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. */ #include <linux/alarmtimer.h> Loading Loading @@ -268,6 +268,18 @@ static bool is_usb_available(struct qpnp_qg *chip) return true; } static bool is_dc_available(struct qpnp_qg *chip) { if (chip->dc_psy) return true; chip->dc_psy = power_supply_get_by_name("dc"); if (!chip->dc_psy) return false; return true; } bool is_usb_present(struct qpnp_qg *chip) { union power_supply_propval pval = {0, }; Loading @@ -279,6 +291,22 @@ bool is_usb_present(struct qpnp_qg *chip) return pval.intval ? true : false; } bool is_dc_present(struct qpnp_qg *chip) { union power_supply_propval pval = {0, }; if (is_dc_available(chip)) power_supply_get_property(chip->dc_psy, POWER_SUPPLY_PROP_PRESENT, &pval); return pval.intval ? true : false; } bool is_input_present(struct qpnp_qg *chip) { return is_usb_present(chip) || is_dc_present(chip); } static bool is_parallel_available(struct qpnp_qg *chip) { if (chip->parallel_psy) Loading Loading @@ -392,3 +420,20 @@ int qg_get_battery_voltage(struct qpnp_qg *chip, int *vbat_uv) return rc; } int qg_get_vbat_avg(struct qpnp_qg *chip, int *vbat_uv) { int rc = 0; u64 last_vbat = 0; rc = qg_read(chip, chip->qg_base + QG_S2_NORMAL_AVG_V_DATA0_REG, (u8 *)&last_vbat, 2); if (rc < 0) { pr_err("Failed to read S2_NORMAL_AVG_V reg, rc=%d\n", rc); return rc; } *vbat_uv = V_RAW_TO_UV(last_vbat); return 0; }
drivers/power/supply/qcom/qg-util.h +4 −1 Original line number Diff line number Diff line /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (c) 2018 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. */ #ifndef __QG_UTIL_H__ Loading @@ -16,11 +16,14 @@ int get_sample_interval(struct qpnp_qg *chip, u32 *sample_interval); int get_fifo_done_time(struct qpnp_qg *chip, bool rt, int *time_ms); int get_rtc_time(unsigned long *rtc_time); bool is_usb_present(struct qpnp_qg *chip); bool is_dc_present(struct qpnp_qg *chip); bool is_input_present(struct qpnp_qg *chip); bool is_parallel_enabled(struct qpnp_qg *chip); int qg_write_monotonic_soc(struct qpnp_qg *chip, int msoc); int qg_get_battery_temp(struct qpnp_qg *chip, int *batt_temp); int qg_get_battery_current(struct qpnp_qg *chip, int *ibat_ua); int qg_get_battery_voltage(struct qpnp_qg *chip, int *vbat_uv); int qg_get_vbat_avg(struct qpnp_qg *chip, int *vbat_uv); s64 qg_iraw_to_ua(struct qpnp_qg *chip, int iraw); #endif