Loading drivers/power/supply/qcom/qg-reg.h +2 −1 Original line number Diff line number Diff line /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. */ #ifndef __QG_REG_H__ Loading Loading @@ -90,6 +90,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 // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. */ #define pr_fmt(fmt) "QG-K: %s: " fmt, __func__ Loading Loading @@ -385,14 +385,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 <= 50) { /* 0.5% */ /* 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 @@ -404,15 +397,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 // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. */ #include <linux/alarmtimer.h> Loading Loading @@ -437,3 +437,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 /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. */ #ifndef __QG_UTIL_H__ Loading @@ -25,5 +25,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 // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. */ #define pr_fmt(fmt) "QG-K: %s: " fmt, __func__ Loading Loading @@ -2202,6 +2202,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 @@ -2271,6 +2274,7 @@ static enum power_supply_property qg_psy_props[] = { POWER_SUPPLY_PROP_CC_SOC, POWER_SUPPLY_PROP_FG_RESET, 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 /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. */ #ifndef __QG_REG_H__ Loading Loading @@ -90,6 +90,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 // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. */ #define pr_fmt(fmt) "QG-K: %s: " fmt, __func__ Loading Loading @@ -385,14 +385,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 <= 50) { /* 0.5% */ /* 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 @@ -404,15 +397,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 // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. */ #include <linux/alarmtimer.h> Loading Loading @@ -437,3 +437,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 /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. */ #ifndef __QG_UTIL_H__ Loading @@ -25,5 +25,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 // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved. */ #define pr_fmt(fmt) "QG-K: %s: " fmt, __func__ Loading Loading @@ -2202,6 +2202,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 @@ -2271,6 +2274,7 @@ static enum power_supply_property qg_psy_props[] = { POWER_SUPPLY_PROP_CC_SOC, POWER_SUPPLY_PROP_FG_RESET, 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