Loading Documentation/devicetree/bindings/power/supply/qcom/qpnp-fg-gen3.txt +30 −0 Original line number Diff line number Diff line Loading @@ -179,6 +179,14 @@ First Level Node - FG Gen3 device Element 0 - Retry value for timer Element 1 - Maximum value for timer - qcom,fg-esr-timer-shutdown Usage: optional Value type: <prop-encoded-array> Definition: Number of cycles between ESR pulses at/after shutdwon.This is defined when TWM (traditional watch mode) is supported. Element 0 - Retry value for timer Element 1 - Maximum value for timer - qcom,fg-esr-pulse-thresh-ma Usage: optional Value type: <u32> Loading Loading @@ -458,6 +466,28 @@ First Level Node - FG Gen3 device Value type: <u32> Definition: The delay in ms for FG to enable BMD after reading RID. - qcom,fg-use-sw-esr Usage: optional Value type: <empty> Definition: A boolean property when defined uses software based ESR during charging. - qcom,fg-disable-esr-pull-dn Usage: optional Value type: <empty> Definition: A boolean property which disables ESR pull-down. This is to be used for debug purposes only. - qcom,fg-sync-sleep-threshold-ma Usage: optional Value type: <u32> Definition: The minimum battery current for FG to enter into sync-sleep. - qcom,fg-disable-in-twm Usage: optional Value type: <empty> Definition: A boolean property which disables FG during TWM entry. ========================================================== Second Level Nodes - Peripherals managed by FG Gen3 driver ========================================================== Loading arch/arm64/boot/dts/qcom/8909w-pm660.dtsi +12 −0 Original line number Diff line number Diff line Loading @@ -552,6 +552,18 @@ &pm660_fg { qcom,battery-data = <&mtp_batterydata>; qcom,fg-rsense-sel = <1>; /* External rsense */ qcom,fg-cutoff-voltage = <3400>; qcom,fg-recharge-voltage = <4100>; qcom,fg-use-sw-esr; qcom,fg-esr-pulse-thresh-ma = <40>; qcom,fg-esr-meas-curr-ma = <60>; qcom,fg-cutoff-current = <50>; qcom,fg-esr-timer-shutdown = <2048 2048>; qcom,fg-esr-timer-asleep = <512 512>; qcom,fg-sync-sleep-threshold-ma = <30>; qcom,fg-disable-in-twm; }; &pm660_pdphy { Loading drivers/power/supply/qcom/fg-core.h +24 −0 Original line number Diff line number Diff line Loading @@ -24,9 +24,11 @@ #include <linux/kernel.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/alarmtimer.h> #include <linux/power_supply.h> #include <linux/regmap.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/string_helpers.h> #include <linux/types.h> #include <linux/uaccess.h> Loading @@ -51,6 +53,7 @@ #define SRAM_WRITE "fg_sram_write" #define PROFILE_LOAD "fg_profile_load" #define TTF_PRIMING "fg_ttf_priming" #define FG_ESR_VOTER "fg_esr_voter" /* Delta BSOC irq votable reasons */ #define DELTA_BSOC_IRQ_VOTER "fg_delta_bsoc_irq" Loading Loading @@ -107,6 +110,11 @@ enum fg_debug_flag { FG_TTF = BIT(8), /* Show time to full */ }; enum awake_reasons { FG_SW_ESR_WAKE = BIT(0), FG_STATUS_NOTIFY_WAKE = BIT(1), }; /* SRAM access */ enum sram_access_flags { FG_IMA_DEFAULT = 0, Loading Loading @@ -182,6 +190,7 @@ enum fg_sram_param_id { FG_SRAM_DELTA_MSOC_THR, FG_SRAM_DELTA_BSOC_THR, FG_SRAM_RECHARGE_SOC_THR, FG_SRAM_SYNC_SLEEP_THR, FG_SRAM_RECHARGE_VBATT_THR, FG_SRAM_KI_COEFF_LOW_DISCHG, FG_SRAM_KI_COEFF_MED_DISCHG, Loading Loading @@ -273,6 +282,9 @@ struct fg_dt_props { bool hold_soc_while_full; bool linearize_soc; bool auto_recharge_soc; bool use_esr_sw; bool disable_esr_pull_dn; bool disable_fg_twm; int cutoff_volt_mv; int empty_volt_mv; int vbatt_low_thr_mv; Loading @@ -287,6 +299,7 @@ struct fg_dt_props { int esr_timer_charging[NUM_ESR_TIMERS]; int esr_timer_awake[NUM_ESR_TIMERS]; int esr_timer_asleep[NUM_ESR_TIMERS]; int esr_timer_shutdown[NUM_ESR_TIMERS]; int rconn_mohms; int esr_clamp_mohms; int cl_start_soc; Loading @@ -309,6 +322,7 @@ struct fg_dt_props { int slope_limit_temp; int esr_pulse_thresh_ma; int esr_meas_curr_ma; int sync_sleep_threshold_ma; int bmd_en_delay_ms; int ki_coeff_full_soc_dischg; int ki_coeff_hi_chg; Loading Loading @@ -439,18 +453,23 @@ struct fg_chip { struct fg_batt_props bp; struct fg_cyc_ctr_data cyc_ctr; struct notifier_block nb; struct notifier_block twm_nb; struct fg_cap_learning cl; struct alarm esr_sw_timer; struct ttf ttf; struct mutex bus_lock; struct mutex sram_rw_lock; struct mutex charge_full_lock; struct mutex qnovo_esr_ctrl_lock; spinlock_t awake_lock; spinlock_t suspend_lock; u32 batt_soc_base; u32 batt_info_base; u32 mem_if_base; u32 rradc_base; u32 wa_flags; u32 esr_wakeup_ms; u32 awake_status; int batt_id_ohms; int ki_coeff_full_soc; int charge_status; Loading Loading @@ -482,6 +501,8 @@ struct fg_chip { bool esr_flt_cold_temp_en; bool slope_limit_en; bool use_ima_single_mode; bool usb_present; bool twm_state; bool use_dma; bool qnovo_enable; bool suspended; Loading @@ -489,6 +510,7 @@ struct fg_chip { struct completion soc_ready; struct delayed_work profile_load_work; struct work_struct status_change_work; struct work_struct esr_sw_work; struct delayed_work ttf_work; struct delayed_work sram_dump_work; struct delayed_work pl_enable_work; Loading Loading @@ -561,4 +583,6 @@ extern int fg_circ_buf_avg(struct fg_circ_buf *buf, int *avg); extern int fg_circ_buf_median(struct fg_circ_buf *buf, int *median); extern int fg_lerp(const struct fg_pt *pts, size_t tablesize, s32 input, s32 *output); void fg_stay_awake(struct fg_chip *chip, int awake_reason); void fg_relax(struct fg_chip *chip, int awake_reason); #endif drivers/power/supply/qcom/fg-reg.h +7 −1 Original line number Diff line number Diff line /* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. /* Copyright (c) 2016-2018, 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 @@ -29,6 +29,7 @@ #define BATT_SOC_STS_CLR(chip) (chip->batt_soc_base + 0x4A) #define BATT_SOC_LOW_PWR_CFG(chip) (chip->batt_soc_base + 0x52) #define BATT_SOC_LOW_PWR_STS(chip) (chip->batt_soc_base + 0x56) #define BATT_SOC_RST_CTRL0(chip) (chip->batt_soc_base + 0xBA) /* BATT_SOC_INT_RT_STS */ #define SOC_READY_BIT BIT(1) Loading @@ -40,6 +41,11 @@ /* BATT_SOC_RESTART */ #define RESTART_GO_BIT BIT(0) /* BATT_SOC_RST_CTRL0 */ #define BCL_RST_BIT BIT(2) #define MEM_RST_BIT BIT(1) #define ALG_RST_BIT BIT(0) /* FG_BATT_INFO register definitions */ #define BATT_INFO_BATT_TEMP_STS(chip) (chip->batt_info_base + 0x06) #define BATT_INFO_SYS_BATT(chip) (chip->batt_info_base + 0x07) Loading drivers/power/supply/qcom/fg-util.c +26 −2 Original line number Diff line number Diff line /* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. /* Copyright (c) 2016-2018, 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 @@ -471,7 +471,7 @@ int fg_masked_write(struct fg_chip *chip, int addr, u8 mask, u8 val) return -ENXIO; mutex_lock(&chip->bus_lock); sec_access = (addr & 0x00FF) > 0xD0; sec_access = (addr & 0x00FF) > 0xB8; if (sec_access) { rc = regmap_write(chip->regmap, (addr & 0xFF00) | 0xD0, 0xA5); if (rc < 0) { Loading Loading @@ -999,3 +999,27 @@ int fg_debugfs_create(struct fg_chip *chip) debugfs_remove_recursive(chip->dfs_root); return -ENOMEM; } void fg_stay_awake(struct fg_chip *chip, int awake_reason) { spin_lock(&chip->awake_lock); if (!chip->awake_status) pm_stay_awake(chip->dev); chip->awake_status |= awake_reason; spin_unlock(&chip->awake_lock); } void fg_relax(struct fg_chip *chip, int awake_reason) { spin_lock(&chip->awake_lock); chip->awake_status &= ~awake_reason; if (!chip->awake_status) pm_relax(chip->dev); spin_unlock(&chip->awake_lock); } Loading
Documentation/devicetree/bindings/power/supply/qcom/qpnp-fg-gen3.txt +30 −0 Original line number Diff line number Diff line Loading @@ -179,6 +179,14 @@ First Level Node - FG Gen3 device Element 0 - Retry value for timer Element 1 - Maximum value for timer - qcom,fg-esr-timer-shutdown Usage: optional Value type: <prop-encoded-array> Definition: Number of cycles between ESR pulses at/after shutdwon.This is defined when TWM (traditional watch mode) is supported. Element 0 - Retry value for timer Element 1 - Maximum value for timer - qcom,fg-esr-pulse-thresh-ma Usage: optional Value type: <u32> Loading Loading @@ -458,6 +466,28 @@ First Level Node - FG Gen3 device Value type: <u32> Definition: The delay in ms for FG to enable BMD after reading RID. - qcom,fg-use-sw-esr Usage: optional Value type: <empty> Definition: A boolean property when defined uses software based ESR during charging. - qcom,fg-disable-esr-pull-dn Usage: optional Value type: <empty> Definition: A boolean property which disables ESR pull-down. This is to be used for debug purposes only. - qcom,fg-sync-sleep-threshold-ma Usage: optional Value type: <u32> Definition: The minimum battery current for FG to enter into sync-sleep. - qcom,fg-disable-in-twm Usage: optional Value type: <empty> Definition: A boolean property which disables FG during TWM entry. ========================================================== Second Level Nodes - Peripherals managed by FG Gen3 driver ========================================================== Loading
arch/arm64/boot/dts/qcom/8909w-pm660.dtsi +12 −0 Original line number Diff line number Diff line Loading @@ -552,6 +552,18 @@ &pm660_fg { qcom,battery-data = <&mtp_batterydata>; qcom,fg-rsense-sel = <1>; /* External rsense */ qcom,fg-cutoff-voltage = <3400>; qcom,fg-recharge-voltage = <4100>; qcom,fg-use-sw-esr; qcom,fg-esr-pulse-thresh-ma = <40>; qcom,fg-esr-meas-curr-ma = <60>; qcom,fg-cutoff-current = <50>; qcom,fg-esr-timer-shutdown = <2048 2048>; qcom,fg-esr-timer-asleep = <512 512>; qcom,fg-sync-sleep-threshold-ma = <30>; qcom,fg-disable-in-twm; }; &pm660_pdphy { Loading
drivers/power/supply/qcom/fg-core.h +24 −0 Original line number Diff line number Diff line Loading @@ -24,9 +24,11 @@ #include <linux/kernel.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/alarmtimer.h> #include <linux/power_supply.h> #include <linux/regmap.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/string_helpers.h> #include <linux/types.h> #include <linux/uaccess.h> Loading @@ -51,6 +53,7 @@ #define SRAM_WRITE "fg_sram_write" #define PROFILE_LOAD "fg_profile_load" #define TTF_PRIMING "fg_ttf_priming" #define FG_ESR_VOTER "fg_esr_voter" /* Delta BSOC irq votable reasons */ #define DELTA_BSOC_IRQ_VOTER "fg_delta_bsoc_irq" Loading Loading @@ -107,6 +110,11 @@ enum fg_debug_flag { FG_TTF = BIT(8), /* Show time to full */ }; enum awake_reasons { FG_SW_ESR_WAKE = BIT(0), FG_STATUS_NOTIFY_WAKE = BIT(1), }; /* SRAM access */ enum sram_access_flags { FG_IMA_DEFAULT = 0, Loading Loading @@ -182,6 +190,7 @@ enum fg_sram_param_id { FG_SRAM_DELTA_MSOC_THR, FG_SRAM_DELTA_BSOC_THR, FG_SRAM_RECHARGE_SOC_THR, FG_SRAM_SYNC_SLEEP_THR, FG_SRAM_RECHARGE_VBATT_THR, FG_SRAM_KI_COEFF_LOW_DISCHG, FG_SRAM_KI_COEFF_MED_DISCHG, Loading Loading @@ -273,6 +282,9 @@ struct fg_dt_props { bool hold_soc_while_full; bool linearize_soc; bool auto_recharge_soc; bool use_esr_sw; bool disable_esr_pull_dn; bool disable_fg_twm; int cutoff_volt_mv; int empty_volt_mv; int vbatt_low_thr_mv; Loading @@ -287,6 +299,7 @@ struct fg_dt_props { int esr_timer_charging[NUM_ESR_TIMERS]; int esr_timer_awake[NUM_ESR_TIMERS]; int esr_timer_asleep[NUM_ESR_TIMERS]; int esr_timer_shutdown[NUM_ESR_TIMERS]; int rconn_mohms; int esr_clamp_mohms; int cl_start_soc; Loading @@ -309,6 +322,7 @@ struct fg_dt_props { int slope_limit_temp; int esr_pulse_thresh_ma; int esr_meas_curr_ma; int sync_sleep_threshold_ma; int bmd_en_delay_ms; int ki_coeff_full_soc_dischg; int ki_coeff_hi_chg; Loading Loading @@ -439,18 +453,23 @@ struct fg_chip { struct fg_batt_props bp; struct fg_cyc_ctr_data cyc_ctr; struct notifier_block nb; struct notifier_block twm_nb; struct fg_cap_learning cl; struct alarm esr_sw_timer; struct ttf ttf; struct mutex bus_lock; struct mutex sram_rw_lock; struct mutex charge_full_lock; struct mutex qnovo_esr_ctrl_lock; spinlock_t awake_lock; spinlock_t suspend_lock; u32 batt_soc_base; u32 batt_info_base; u32 mem_if_base; u32 rradc_base; u32 wa_flags; u32 esr_wakeup_ms; u32 awake_status; int batt_id_ohms; int ki_coeff_full_soc; int charge_status; Loading Loading @@ -482,6 +501,8 @@ struct fg_chip { bool esr_flt_cold_temp_en; bool slope_limit_en; bool use_ima_single_mode; bool usb_present; bool twm_state; bool use_dma; bool qnovo_enable; bool suspended; Loading @@ -489,6 +510,7 @@ struct fg_chip { struct completion soc_ready; struct delayed_work profile_load_work; struct work_struct status_change_work; struct work_struct esr_sw_work; struct delayed_work ttf_work; struct delayed_work sram_dump_work; struct delayed_work pl_enable_work; Loading Loading @@ -561,4 +583,6 @@ extern int fg_circ_buf_avg(struct fg_circ_buf *buf, int *avg); extern int fg_circ_buf_median(struct fg_circ_buf *buf, int *median); extern int fg_lerp(const struct fg_pt *pts, size_t tablesize, s32 input, s32 *output); void fg_stay_awake(struct fg_chip *chip, int awake_reason); void fg_relax(struct fg_chip *chip, int awake_reason); #endif
drivers/power/supply/qcom/fg-reg.h +7 −1 Original line number Diff line number Diff line /* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. /* Copyright (c) 2016-2018, 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 @@ -29,6 +29,7 @@ #define BATT_SOC_STS_CLR(chip) (chip->batt_soc_base + 0x4A) #define BATT_SOC_LOW_PWR_CFG(chip) (chip->batt_soc_base + 0x52) #define BATT_SOC_LOW_PWR_STS(chip) (chip->batt_soc_base + 0x56) #define BATT_SOC_RST_CTRL0(chip) (chip->batt_soc_base + 0xBA) /* BATT_SOC_INT_RT_STS */ #define SOC_READY_BIT BIT(1) Loading @@ -40,6 +41,11 @@ /* BATT_SOC_RESTART */ #define RESTART_GO_BIT BIT(0) /* BATT_SOC_RST_CTRL0 */ #define BCL_RST_BIT BIT(2) #define MEM_RST_BIT BIT(1) #define ALG_RST_BIT BIT(0) /* FG_BATT_INFO register definitions */ #define BATT_INFO_BATT_TEMP_STS(chip) (chip->batt_info_base + 0x06) #define BATT_INFO_SYS_BATT(chip) (chip->batt_info_base + 0x07) Loading
drivers/power/supply/qcom/fg-util.c +26 −2 Original line number Diff line number Diff line /* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. /* Copyright (c) 2016-2018, 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 @@ -471,7 +471,7 @@ int fg_masked_write(struct fg_chip *chip, int addr, u8 mask, u8 val) return -ENXIO; mutex_lock(&chip->bus_lock); sec_access = (addr & 0x00FF) > 0xD0; sec_access = (addr & 0x00FF) > 0xB8; if (sec_access) { rc = regmap_write(chip->regmap, (addr & 0xFF00) | 0xD0, 0xA5); if (rc < 0) { Loading Loading @@ -999,3 +999,27 @@ int fg_debugfs_create(struct fg_chip *chip) debugfs_remove_recursive(chip->dfs_root); return -ENOMEM; } void fg_stay_awake(struct fg_chip *chip, int awake_reason) { spin_lock(&chip->awake_lock); if (!chip->awake_status) pm_stay_awake(chip->dev); chip->awake_status |= awake_reason; spin_unlock(&chip->awake_lock); } void fg_relax(struct fg_chip *chip, int awake_reason) { spin_lock(&chip->awake_lock); chip->awake_status &= ~awake_reason; if (!chip->awake_status) pm_relax(chip->dev); spin_unlock(&chip->awake_lock); }