Loading drivers/power/supply/qcom/qg-reg.h +2 −1 Original line number Diff line number Diff line /* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. /* Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading Loading @@ -97,6 +97,7 @@ #define QG_POST_ESR_I_DATA0_REG 0x7E #define QG_S2_NORMAL_AVG_V_DATA0_REG 0x80 #define QG_S2_NORMAL_AVG_I_DATA0_REG 0x82 #define QG_V_ACCUM_DATA0_RT_REG 0x88 #define QG_I_ACCUM_DATA0_RT_REG 0x8B Loading drivers/power/supply/qcom/qg-soc.c +15 −12 Original line number Diff line number Diff line /* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. /* Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading Loading @@ -283,14 +283,7 @@ int qg_adjust_sys_soc(struct qpnp_qg *chip) /* TCSS */ chip->sys_soc = qg_process_tcss_soc(chip, chip->sys_soc); if (chip->sys_soc < 100) { /* Hold SOC to 1% of VBAT has not dropped below cutoff */ rc = qg_get_battery_voltage(chip, &vbat_uv); if (!rc && vbat_uv >= (vcutoff_uv + VBAT_LOW_HYST_UV)) soc = 1; else soc = 0; } else if (chip->sys_soc == QG_MAX_SOC) { if (chip->sys_soc == QG_MAX_SOC) { soc = FULL_SOC; } else if (chip->sys_soc >= (QG_MAX_SOC - 100)) { /* Hold SOC to 100% if we are dropping from 100 to 99 */ Loading @@ -302,15 +295,25 @@ int qg_adjust_sys_soc(struct qpnp_qg *chip) soc = DIV_ROUND_CLOSEST(chip->sys_soc, 100); } qg_dbg(chip, QG_DEBUG_SOC, "sys_soc=%d adjusted sys_soc=%d\n", chip->sys_soc, soc); /* FVSS */ soc = qg_process_fvss_soc(chip, soc); /* BASS */ soc = qg_process_bass_soc(chip, soc); if (soc == 0) { /* Hold SOC to 1% if we have not dropped below cutoff */ rc = qg_get_vbat_avg(chip, &vbat_uv); if (!rc && (vbat_uv >= (vcutoff_uv + VBAT_LOW_HYST_UV))) { soc = 1; qg_dbg(chip, QG_DEBUG_SOC, "vbat_uv=%duV holding SOC to 1%\n", vbat_uv); } } qg_dbg(chip, QG_DEBUG_SOC, "sys_soc=%d adjusted sys_soc=%d\n", chip->sys_soc, soc); chip->last_adj_ssoc = soc; return soc; Loading drivers/power/supply/qcom/qg-util.c +19 −1 Original line number Diff line number Diff line /* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. /* Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading Loading @@ -444,3 +444,21 @@ int qg_get_vbat_avg(struct qpnp_qg *chip, int *vbat_uv) return 0; } int qg_get_ibat_avg(struct qpnp_qg *chip, int *ibat_ua) { int rc = 0; int last_ibat = 0; rc = qg_read(chip, chip->qg_base + QG_S2_NORMAL_AVG_I_DATA0_REG, (u8 *)&last_ibat, 2); if (rc < 0) { pr_err("Failed to read S2_NORMAL_AVG_I reg, rc=%d\n", rc); return rc; } last_ibat = sign_extend32(last_ibat, 15); *ibat_ua = qg_iraw_to_ua(chip, last_ibat); return 0; } drivers/power/supply/qcom/qg-util.h +2 −1 Original line number Diff line number Diff line /* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. /* Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading Loading @@ -31,5 +31,6 @@ 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); int qg_get_ibat_avg(struct qpnp_qg *chip, int *ibat_ua); #endif drivers/power/supply/qcom/qpnp-qg.c +5 −1 Original line number Diff line number Diff line /* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. /* Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading Loading @@ -2163,6 +2163,9 @@ static int qg_psy_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_VOLTAGE_AVG: rc = qg_get_vbat_avg(chip, &pval->intval); break; case POWER_SUPPLY_PROP_CURRENT_AVG: rc = qg_get_ibat_avg(chip, &pval->intval); break; case POWER_SUPPLY_PROP_POWER_NOW: rc = qg_get_power(chip, &pval->intval, false); break; Loading Loading @@ -2232,6 +2235,7 @@ static enum power_supply_property qg_psy_props[] = { POWER_SUPPLY_PROP_FG_RESET, POWER_SUPPLY_PROP_CC_SOC, POWER_SUPPLY_PROP_VOLTAGE_AVG, POWER_SUPPLY_PROP_CURRENT_AVG, POWER_SUPPLY_PROP_POWER_AVG, POWER_SUPPLY_PROP_POWER_NOW, POWER_SUPPLY_PROP_SCALE_MODE_EN, Loading Loading
drivers/power/supply/qcom/qg-reg.h +2 −1 Original line number Diff line number Diff line /* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. /* Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading Loading @@ -97,6 +97,7 @@ #define QG_POST_ESR_I_DATA0_REG 0x7E #define QG_S2_NORMAL_AVG_V_DATA0_REG 0x80 #define QG_S2_NORMAL_AVG_I_DATA0_REG 0x82 #define QG_V_ACCUM_DATA0_RT_REG 0x88 #define QG_I_ACCUM_DATA0_RT_REG 0x8B Loading
drivers/power/supply/qcom/qg-soc.c +15 −12 Original line number Diff line number Diff line /* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. /* Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading Loading @@ -283,14 +283,7 @@ int qg_adjust_sys_soc(struct qpnp_qg *chip) /* TCSS */ chip->sys_soc = qg_process_tcss_soc(chip, chip->sys_soc); if (chip->sys_soc < 100) { /* Hold SOC to 1% of VBAT has not dropped below cutoff */ rc = qg_get_battery_voltage(chip, &vbat_uv); if (!rc && vbat_uv >= (vcutoff_uv + VBAT_LOW_HYST_UV)) soc = 1; else soc = 0; } else if (chip->sys_soc == QG_MAX_SOC) { if (chip->sys_soc == QG_MAX_SOC) { soc = FULL_SOC; } else if (chip->sys_soc >= (QG_MAX_SOC - 100)) { /* Hold SOC to 100% if we are dropping from 100 to 99 */ Loading @@ -302,15 +295,25 @@ int qg_adjust_sys_soc(struct qpnp_qg *chip) soc = DIV_ROUND_CLOSEST(chip->sys_soc, 100); } qg_dbg(chip, QG_DEBUG_SOC, "sys_soc=%d adjusted sys_soc=%d\n", chip->sys_soc, soc); /* FVSS */ soc = qg_process_fvss_soc(chip, soc); /* BASS */ soc = qg_process_bass_soc(chip, soc); if (soc == 0) { /* Hold SOC to 1% if we have not dropped below cutoff */ rc = qg_get_vbat_avg(chip, &vbat_uv); if (!rc && (vbat_uv >= (vcutoff_uv + VBAT_LOW_HYST_UV))) { soc = 1; qg_dbg(chip, QG_DEBUG_SOC, "vbat_uv=%duV holding SOC to 1%\n", vbat_uv); } } qg_dbg(chip, QG_DEBUG_SOC, "sys_soc=%d adjusted sys_soc=%d\n", chip->sys_soc, soc); chip->last_adj_ssoc = soc; return soc; Loading
drivers/power/supply/qcom/qg-util.c +19 −1 Original line number Diff line number Diff line /* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. /* Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading Loading @@ -444,3 +444,21 @@ int qg_get_vbat_avg(struct qpnp_qg *chip, int *vbat_uv) return 0; } int qg_get_ibat_avg(struct qpnp_qg *chip, int *ibat_ua) { int rc = 0; int last_ibat = 0; rc = qg_read(chip, chip->qg_base + QG_S2_NORMAL_AVG_I_DATA0_REG, (u8 *)&last_ibat, 2); if (rc < 0) { pr_err("Failed to read S2_NORMAL_AVG_I reg, rc=%d\n", rc); return rc; } last_ibat = sign_extend32(last_ibat, 15); *ibat_ua = qg_iraw_to_ua(chip, last_ibat); return 0; }
drivers/power/supply/qcom/qg-util.h +2 −1 Original line number Diff line number Diff line /* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. /* Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading Loading @@ -31,5 +31,6 @@ 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); int qg_get_ibat_avg(struct qpnp_qg *chip, int *ibat_ua); #endif
drivers/power/supply/qcom/qpnp-qg.c +5 −1 Original line number Diff line number Diff line /* Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. /* Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and Loading Loading @@ -2163,6 +2163,9 @@ static int qg_psy_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_VOLTAGE_AVG: rc = qg_get_vbat_avg(chip, &pval->intval); break; case POWER_SUPPLY_PROP_CURRENT_AVG: rc = qg_get_ibat_avg(chip, &pval->intval); break; case POWER_SUPPLY_PROP_POWER_NOW: rc = qg_get_power(chip, &pval->intval, false); break; Loading Loading @@ -2232,6 +2235,7 @@ static enum power_supply_property qg_psy_props[] = { POWER_SUPPLY_PROP_FG_RESET, POWER_SUPPLY_PROP_CC_SOC, POWER_SUPPLY_PROP_VOLTAGE_AVG, POWER_SUPPLY_PROP_CURRENT_AVG, POWER_SUPPLY_PROP_POWER_AVG, POWER_SUPPLY_PROP_POWER_NOW, POWER_SUPPLY_PROP_SCALE_MODE_EN, Loading