Loading drivers/power/supply/qcom/qg-core.h +2 −0 Original line number Diff line number Diff line Loading @@ -143,6 +143,8 @@ struct qpnp_qg { int batt_soc; int cc_soc; int full_soc; int sys_soc; int last_adj_ssoc; struct alarm alarm_timer; u32 sdam_data[SDAM_MAX]; Loading drivers/power/supply/qcom/qg-soc.c +37 −0 Original line number Diff line number Diff line Loading @@ -17,15 +17,19 @@ #include <linux/module.h> #include <linux/power_supply.h> #include <uapi/linux/qg.h> #include <uapi/linux/qg-profile.h> #include "fg-alg.h" #include "qg-sdam.h" #include "qg-core.h" #include "qg-reg.h" #include "qg-util.h" #include "qg-defs.h" #include "qg-soc.h" #define DEFAULT_UPDATE_TIME_MS 64000 #define SOC_SCALE_HYST_MS 2000 #define VBAT_LOW_HYST_UV 50000 #define FULL_SOC 100 static int qg_delta_soc_interval_ms = 20000; module_param_named( Loading @@ -37,6 +41,39 @@ module_param_named( soc_cold_interval_ms, qg_delta_soc_cold_interval_ms, int, 0600 ); int qg_adjust_sys_soc(struct qpnp_qg *chip) { int soc, vbat_uv, rc; int vcutoff_uv = chip->dt.vbatt_cutoff_mv * 1000; chip->sys_soc = CAP(QG_MIN_SOC, QG_MAX_SOC, chip->sys_soc); if (chip->sys_soc == QG_MIN_SOC) { /* 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) { soc = FULL_SOC; } else if (chip->sys_soc >= (QG_MAX_SOC - 100)) { /* Hold SOC to 100% if we are dropping from 100 to 99 */ if (chip->last_adj_ssoc == FULL_SOC) soc = FULL_SOC; else /* Hold SOC at 99% until we hit 100% */ soc = FULL_SOC - 1; } else { soc = DIV_ROUND_CLOSEST(chip->sys_soc, 100); } qg_dbg(chip, QG_DEBUG_SOC, "last_adj_sys_soc=%d adj_sys_soc=%d\n", chip->last_adj_ssoc, soc); chip->last_adj_ssoc = soc; return soc; } static void get_next_update_time(struct qpnp_qg *chip) { int soc_points = 0, batt_temp = 0; Loading drivers/power/supply/qcom/qg-soc.h +1 −0 Original line number Diff line number Diff line Loading @@ -16,5 +16,6 @@ int qg_scale_soc(struct qpnp_qg *chip, bool force_soc); int qg_soc_init(struct qpnp_qg *chip); void qg_soc_exit(struct qpnp_qg *chip); int qg_adjust_sys_soc(struct qpnp_qg *chip); #endif /* __QG_SOC_H__ */ drivers/power/supply/qcom/qg-util.c +22 −0 Original line number Diff line number Diff line Loading @@ -367,3 +367,25 @@ int qg_get_battery_current(struct qpnp_qg *chip, int *ibat_ua) BURST_AVG_HOLD_FOR_READ_BIT, 0); return rc; } int qg_get_battery_voltage(struct qpnp_qg *chip, int *vbat_uv) { int rc = 0; u64 last_vbat = 0; if (chip->battery_missing) { *vbat_uv = 3700000; return 0; } rc = qg_read(chip, chip->qg_base + QG_LAST_ADC_V_DATA0_REG, (u8 *)&last_vbat, 2); if (rc < 0) { pr_err("Failed to read LAST_ADV_V reg, rc=%d\n", rc); return rc; } *vbat_uv = V_RAW_TO_UV(last_vbat); return rc; } drivers/power/supply/qcom/qg-util.h +1 −0 Original line number Diff line number Diff line Loading @@ -26,5 +26,6 @@ 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); #endif Loading
drivers/power/supply/qcom/qg-core.h +2 −0 Original line number Diff line number Diff line Loading @@ -143,6 +143,8 @@ struct qpnp_qg { int batt_soc; int cc_soc; int full_soc; int sys_soc; int last_adj_ssoc; struct alarm alarm_timer; u32 sdam_data[SDAM_MAX]; Loading
drivers/power/supply/qcom/qg-soc.c +37 −0 Original line number Diff line number Diff line Loading @@ -17,15 +17,19 @@ #include <linux/module.h> #include <linux/power_supply.h> #include <uapi/linux/qg.h> #include <uapi/linux/qg-profile.h> #include "fg-alg.h" #include "qg-sdam.h" #include "qg-core.h" #include "qg-reg.h" #include "qg-util.h" #include "qg-defs.h" #include "qg-soc.h" #define DEFAULT_UPDATE_TIME_MS 64000 #define SOC_SCALE_HYST_MS 2000 #define VBAT_LOW_HYST_UV 50000 #define FULL_SOC 100 static int qg_delta_soc_interval_ms = 20000; module_param_named( Loading @@ -37,6 +41,39 @@ module_param_named( soc_cold_interval_ms, qg_delta_soc_cold_interval_ms, int, 0600 ); int qg_adjust_sys_soc(struct qpnp_qg *chip) { int soc, vbat_uv, rc; int vcutoff_uv = chip->dt.vbatt_cutoff_mv * 1000; chip->sys_soc = CAP(QG_MIN_SOC, QG_MAX_SOC, chip->sys_soc); if (chip->sys_soc == QG_MIN_SOC) { /* 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) { soc = FULL_SOC; } else if (chip->sys_soc >= (QG_MAX_SOC - 100)) { /* Hold SOC to 100% if we are dropping from 100 to 99 */ if (chip->last_adj_ssoc == FULL_SOC) soc = FULL_SOC; else /* Hold SOC at 99% until we hit 100% */ soc = FULL_SOC - 1; } else { soc = DIV_ROUND_CLOSEST(chip->sys_soc, 100); } qg_dbg(chip, QG_DEBUG_SOC, "last_adj_sys_soc=%d adj_sys_soc=%d\n", chip->last_adj_ssoc, soc); chip->last_adj_ssoc = soc; return soc; } static void get_next_update_time(struct qpnp_qg *chip) { int soc_points = 0, batt_temp = 0; Loading
drivers/power/supply/qcom/qg-soc.h +1 −0 Original line number Diff line number Diff line Loading @@ -16,5 +16,6 @@ int qg_scale_soc(struct qpnp_qg *chip, bool force_soc); int qg_soc_init(struct qpnp_qg *chip); void qg_soc_exit(struct qpnp_qg *chip); int qg_adjust_sys_soc(struct qpnp_qg *chip); #endif /* __QG_SOC_H__ */
drivers/power/supply/qcom/qg-util.c +22 −0 Original line number Diff line number Diff line Loading @@ -367,3 +367,25 @@ int qg_get_battery_current(struct qpnp_qg *chip, int *ibat_ua) BURST_AVG_HOLD_FOR_READ_BIT, 0); return rc; } int qg_get_battery_voltage(struct qpnp_qg *chip, int *vbat_uv) { int rc = 0; u64 last_vbat = 0; if (chip->battery_missing) { *vbat_uv = 3700000; return 0; } rc = qg_read(chip, chip->qg_base + QG_LAST_ADC_V_DATA0_REG, (u8 *)&last_vbat, 2); if (rc < 0) { pr_err("Failed to read LAST_ADV_V reg, rc=%d\n", rc); return rc; } *vbat_uv = V_RAW_TO_UV(last_vbat); return rc; }
drivers/power/supply/qcom/qg-util.h +1 −0 Original line number Diff line number Diff line Loading @@ -26,5 +26,6 @@ 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); #endif