Loading drivers/power/supply/qcom/battery.c +24 −29 Original line number Diff line number Diff line Loading @@ -94,12 +94,11 @@ struct pl_data { struct class qcom_batt_class; struct wakeup_source *pl_ws; struct notifier_block nb; struct charger_param *chg_param; bool pl_disable; bool cp_disabled; int taper_entry_fv; int main_fcc_max; int fcc_step_size_ua; int fcc_step_delay_ms; /* debugfs directory */ struct dentry *dfs_root; u32 float_voltage_uv; Loading Loading @@ -523,8 +522,6 @@ ATTRIBUTE_GROUPS(batt_class); * FCC * **********/ #define EFFICIENCY_PCT 80 #define DEFAULT_FCC_STEP_SIZE_UA 100000 #define DEFAULT_FCC_STEP_UPDATE_DELAY_MS 1000 #define STEP_UP 1 #define STEP_DOWN -1 static void get_fcc_split(struct pl_data *chip, int total_ua, Loading Loading @@ -627,7 +624,7 @@ static void get_fcc_stepper_params(struct pl_data *chip, int main_fcc_ua, { int main_set_fcc_ua, total_fcc_ua; if (!chip->fcc_step_size_ua) { if (!chip->chg_param->fcc_step_size_ua) { pr_err("Invalid fcc stepper step size, value 0\n"); return; } Loading Loading @@ -658,16 +655,18 @@ static void get_fcc_stepper_params(struct pl_data *chip, int main_fcc_ua, chip->main_step_fcc_dir = (main_fcc_ua > chip->main_fcc_ua) ? STEP_UP : STEP_DOWN; chip->main_step_fcc_count = abs((main_fcc_ua - chip->main_fcc_ua) / chip->fcc_step_size_ua); chip->chg_param->fcc_step_size_ua); chip->main_step_fcc_residual = abs((main_fcc_ua - chip->main_fcc_ua) % chip->fcc_step_size_ua); chip->chg_param->fcc_step_size_ua); chip->parallel_step_fcc_dir = (parallel_fcc_ua > chip->slave_fcc_ua) ? STEP_UP : STEP_DOWN; chip->parallel_step_fcc_count = abs((parallel_fcc_ua - chip->slave_fcc_ua) / chip->fcc_step_size_ua); chip->parallel_step_fcc_residual = abs((parallel_fcc_ua - chip->slave_fcc_ua) % chip->fcc_step_size_ua); chip->parallel_step_fcc_count = abs((parallel_fcc_ua - chip->slave_fcc_ua) / chip->chg_param->fcc_step_size_ua); chip->parallel_step_fcc_residual = abs((parallel_fcc_ua - chip->slave_fcc_ua) % chip->chg_param->fcc_step_size_ua); skip_fcc_step_update: if (chip->parallel_step_fcc_count || chip->parallel_step_fcc_residual Loading Loading @@ -958,19 +957,20 @@ static void fcc_stepper_work(struct work_struct *work) } if (chip->main_step_fcc_count) { main_fcc += (chip->fcc_step_size_ua * chip->main_step_fcc_dir); main_fcc += (chip->chg_param->fcc_step_size_ua * chip->main_step_fcc_dir); chip->main_step_fcc_count--; reschedule_ms = chip->fcc_step_delay_ms; reschedule_ms = chip->chg_param->fcc_step_delay_ms; } else if (chip->main_step_fcc_residual) { main_fcc += chip->main_step_fcc_residual; chip->main_step_fcc_residual = 0; } if (chip->parallel_step_fcc_count) { parallel_fcc += (chip->fcc_step_size_ua * chip->parallel_step_fcc_dir); parallel_fcc += (chip->chg_param->fcc_step_size_ua * chip->parallel_step_fcc_dir); chip->parallel_step_fcc_count--; reschedule_ms = chip->fcc_step_delay_ms; reschedule_ms = chip->chg_param->fcc_step_delay_ms; } else if (chip->parallel_step_fcc_residual) { parallel_fcc += chip->parallel_step_fcc_residual; chip->parallel_step_fcc_residual = 0; Loading Loading @@ -1817,22 +1817,11 @@ static int pl_determine_initial_status(struct pl_data *chip) static void pl_config_init(struct pl_data *chip, int smb_version) { chip->fcc_step_size_ua = DEFAULT_FCC_STEP_SIZE_UA; chip->fcc_step_delay_ms = DEFAULT_FCC_STEP_UPDATE_DELAY_MS; switch (smb_version) { case PM8150B_SUBTYPE: chip->fcc_step_delay_ms = 100; break; case PMI8998_SUBTYPE: case PM660_SUBTYPE: chip->wa_flags = AICL_RERUN_WA_BIT | FORCE_INOV_DISABLE_BIT; break; case PMI632_SUBTYPE: break; case PM7250B_SUBTYPE: chip->fcc_step_delay_ms = 100; break; default: break; } Loading @@ -1857,11 +1846,16 @@ static void qcom_batt_create_debugfs(struct pl_data *chip) } #define DEFAULT_RESTRICTED_CURRENT_UA 1000000 int qcom_batt_init(int smb_version) int qcom_batt_init(struct charger_param *chg_param) { struct pl_data *chip; int rc = 0; if (!chg_param) { pr_err("invalid charger parameter\n"); return -EINVAL; } /* initialize just once */ if (the_chip) { pr_err("was initialized earlier. Failing now\n"); Loading @@ -1875,7 +1869,8 @@ int qcom_batt_init(int smb_version) qcom_batt_create_debugfs(chip); chip->slave_pct = 50; pl_config_init(chip, smb_version); chip->chg_param = chg_param; pl_config_init(chip, chg_param->smb_version); chip->restricted_current = DEFAULT_RESTRICTED_CURRENT_UA; chip->pl_ws = wakeup_source_register("qcom-battery"); Loading drivers/power/supply/qcom/battery.h +9 −2 Original line number Diff line number Diff line /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (c) 2017 The Linux Foundation. All rights reserved. * Copyright (c) 2017, 2019 The Linux Foundation. All rights reserved. */ #ifndef __BATTERY_H #define __BATTERY_H int qcom_batt_init(int smb_version); struct charger_param { u32 fcc_step_delay_ms; u32 fcc_step_size_ua; u32 smb_version; }; int qcom_batt_init(struct charger_param *param); void qcom_batt_deinit(void); #endif /* __BATTERY_H */ drivers/power/supply/qcom/qpnp-smb5.c +31 −16 Original line number Diff line number Diff line Loading @@ -325,20 +325,20 @@ static int smb5_chg_config_init(struct smb5 *chip) switch (pmic_rev_id->pmic_subtype) { case PM8150B_SUBTYPE: chip->chg.smb_version = PM8150B_SUBTYPE; chip->chg.chg_param.smb_version = PM8150B_SUBTYPE; chg->param = smb5_pm8150b_params; chg->name = "pm8150b_charger"; chg->wa_flags |= CHG_TERMINATION_WA; break; case PM7250B_SUBTYPE: chip->chg.smb_version = PM7250B_SUBTYPE; chip->chg.chg_param.smb_version = PM7250B_SUBTYPE; chg->param = smb5_pm8150b_params; chg->name = "pm7250b_charger"; chg->wa_flags |= CHG_TERMINATION_WA; chg->uusb_moisture_protection_capable = true; break; case PM6150_SUBTYPE: chip->chg.smb_version = PM6150_SUBTYPE; chip->chg.chg_param.smb_version = PM6150_SUBTYPE; chg->param = smb5_pm8150b_params; chg->name = "pm6150_charger"; chg->wa_flags |= SW_THERM_REGULATION_WA | CHG_TERMINATION_WA; Loading @@ -347,7 +347,7 @@ static int smb5_chg_config_init(struct smb5 *chip) chg->main_fcc_max = PM6150_MAX_FCC_UA; break; case PMI632_SUBTYPE: chip->chg.smb_version = PMI632_SUBTYPE; chip->chg.chg_param.smb_version = PMI632_SUBTYPE; chg->wa_flags |= WEAK_ADAPTER_WA | USBIN_OV_WA | CHG_TERMINATION_WA | USBIN_ADC_WA | SKIP_MISC_PBS_IRQ_WA; Loading Loading @@ -435,6 +435,8 @@ static int smb5_configure_internal_pull(struct smb_charger *chg, int type, #define OTG_DEFAULT_DEGLITCH_TIME_MS 50 #define DEFAULT_WD_BARK_TIME 64 #define DEFAULT_WD_SNARL_TIME_8S 0x07 #define DEFAULT_FCC_STEP_SIZE_UA 100000 #define DEFAULT_FCC_STEP_UPDATE_DELAY_MS 1000 static int smb5_parse_dt_misc(struct smb5 *chip, struct device_node *node) { int rc = 0, byte_len; Loading Loading @@ -571,6 +573,17 @@ static int smb5_parse_dt_misc(struct smb5 *chip, struct device_node *node) chip->dt.adc_based_aicl = of_property_read_bool(node, "qcom,adc-based-aicl"); of_property_read_u32(node, "qcom,fcc-step-delay-ms", &chg->chg_param.fcc_step_delay_ms); if (chg->chg_param.fcc_step_delay_ms <= 0) chg->chg_param.fcc_step_delay_ms = DEFAULT_FCC_STEP_UPDATE_DELAY_MS; of_property_read_u32(node, "qcom,fcc-step-size-ua", &chg->chg_param.fcc_step_size_ua); if (chg->chg_param.fcc_step_size_ua <= 0) chg->chg_param.fcc_step_size_ua = DEFAULT_FCC_STEP_SIZE_UA; return 0; } Loading Loading @@ -643,7 +656,8 @@ static int smb5_parse_dt_currents(struct smb5 *chip, struct device_node *node) rc = of_property_read_u32(node, "qcom,otg-cl-ua", &chg->otg_cl_ua); if (rc < 0) chg->otg_cl_ua = (chip->chg.smb_version == PMI632_SUBTYPE) ? chg->otg_cl_ua = (chip->chg.chg_param.smb_version == PMI632_SUBTYPE) ? MICRO_1PA : MICRO_3PA; rc = of_property_read_u32(node, "qcom,chg-term-src", Loading Loading @@ -1292,7 +1306,7 @@ static int smb5_usb_main_set_prop(struct power_supply *psy, rc = smblib_set_icl_current(chg, val->intval); break; case POWER_SUPPLY_PROP_FLASH_ACTIVE: if ((chg->smb_version == PMI632_SUBTYPE) if ((chg->chg_param.smb_version == PMI632_SUBTYPE) && (chg->flash_active != val->intval)) { chg->flash_active = val->intval; Loading Loading @@ -2057,7 +2071,7 @@ static int smb5_configure_typec(struct smb_charger *chg) return rc; } if (chg->smb_version != PMI632_SUBTYPE) { if (chg->chg_param.smb_version != PMI632_SUBTYPE) { rc = smblib_masked_write(chg, USBIN_LOAD_CFG_REG, USBIN_IN_COLLAPSE_GF_SEL_MASK | USBIN_AICL_STEP_TIMING_SEL_MASK, Loading Loading @@ -2118,7 +2132,8 @@ static int smb5_configure_micro_usb(struct smb_charger *chg) } /* Disable periodic monitoring of CC_ID pin */ rc = smblib_write(chg, ((chg->smb_version == PMI632_SUBTYPE) ? rc = smblib_write(chg, ((chg->chg_param.smb_version == PMI632_SUBTYPE) ? PMI632_TYPEC_U_USB_WATER_PROTECTION_CFG_REG : TYPEC_U_USB_WATER_PROTECTION_CFG_REG), 0); if (rc < 0) { Loading @@ -2144,7 +2159,7 @@ static int smb5_configure_iterm_thresholds_adc(struct smb5 *chip) s16 raw_hi_thresh, raw_lo_thresh, max_limit_ma; struct smb_charger *chg = &chip->chg; if (chip->chg.smb_version == PMI632_SUBTYPE) if (chip->chg.chg_param.smb_version == PMI632_SUBTYPE) max_limit_ma = ITERM_LIMITS_PMI632_MA; else max_limit_ma = ITERM_LIMITS_PM8150B_MA; Loading Loading @@ -2205,7 +2220,7 @@ static int smb5_configure_iterm_thresholds(struct smb5 *chip) switch (chip->dt.term_current_src) { case ITERM_SRC_ADC: if (chip->chg.smb_version == PM8150B_SUBTYPE) { if (chip->chg.chg_param.smb_version == PM8150B_SUBTYPE) { rc = smblib_masked_write(chg, CHGR_ADC_TERM_CFG_REG, TERM_BASED_ON_SYNC_CONV_OR_SAMPLE_CNT, TERM_BASED_ON_SAMPLE_CNT); Loading Loading @@ -2277,7 +2292,7 @@ static int smb5_init_dc_peripheral(struct smb_charger *chg) int rc = 0; /* PMI632 does not have DC peripheral */ if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) return 0; /* Set DCIN ICL to 100 mA */ Loading Loading @@ -2415,7 +2430,7 @@ static int smb5_init_connector_type(struct smb_charger *chg) * PMI632 can have the connector type defined by a dedicated register * PMI632_TYPEC_MICRO_USB_MODE_REG or by a common TYPEC_U_USB_CFG_REG. */ if (chg->smb_version == PMI632_SUBTYPE) { if (chg->chg_param.smb_version == PMI632_SUBTYPE) { rc = smblib_read(chg, PMI632_TYPEC_MICRO_USB_MODE_REG, &val); if (rc < 0) { dev_err(chg->dev, "Couldn't read USB mode rc=%d\n", rc); Loading Loading @@ -2460,7 +2475,7 @@ static int smb5_init_connector_type(struct smb_charger *chg) * boots with charger connected. * - Initialize flash module for PMI632 */ if (chg->smb_version == PMI632_SUBTYPE) { if (chg->chg_param.smb_version == PMI632_SUBTYPE) { schgm_flash_init(chg); smblib_rerun_apsd_if_required(chg); } Loading Loading @@ -3418,7 +3433,7 @@ static int smb5_probe(struct platform_device *pdev) } } switch (chg->smb_version) { switch (chg->chg_param.smb_version) { case PM8150B_SUBTYPE: case PM6150_SUBTYPE: case PM7250B_SUBTYPE: Loading drivers/power/supply/qcom/smb5-lib.c +20 −20 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ #include <linux/ktime.h> #include "smb5-lib.h" #include "smb5-reg.h" #include "battery.h" #include "schgm-flash.h" #include "step-chg-jeita.h" #include "storm-watch.h" Loading Loading @@ -756,7 +755,7 @@ static int smblib_usb_pd_adapter_allowance_override(struct smb_charger *chg, { int rc = 0; if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) return 0; rc = smblib_write(chg, USBIN_ADAPTER_ALLOW_OVERRIDE_REG, Loading Loading @@ -803,7 +802,7 @@ static int smblib_set_usb_pd_allowed_voltage(struct smb_charger *chg, int rc, aicl_threshold; u8 vbus_allowance; if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) return 0; if (chg->pd_active == POWER_SUPPLY_PD_PPS_ACTIVE) { Loading Loading @@ -1484,8 +1483,8 @@ static int smblib_set_moisture_protection(struct smb_charger *chg, /* Set 1% duty cycle on ID detection */ rc = smblib_masked_write(chg, ((chg->smb_version == PMI632_SUBTYPE) ? PMI632_TYPEC_U_USB_WATER_PROTECTION_CFG_REG : ((chg->chg_param.smb_version == PMI632_SUBTYPE) ? PMI632_TYPEC_U_USB_WATER_PROTECTION_CFG_REG : TYPEC_U_USB_WATER_PROTECTION_CFG_REG), EN_MICRO_USB_WATER_PROTECTION_BIT | MICRO_USB_DETECTION_ON_TIME_CFG_MASK | Loading Loading @@ -1517,8 +1516,9 @@ static int smblib_set_moisture_protection(struct smb_charger *chg, } /* Disable periodic monitoring of CC_ID pin */ rc = smblib_write(chg, ((chg->smb_version == PMI632_SUBTYPE) ? PMI632_TYPEC_U_USB_WATER_PROTECTION_CFG_REG : rc = smblib_write(chg, ((chg->chg_param.smb_version == PMI632_SUBTYPE) ? PMI632_TYPEC_U_USB_WATER_PROTECTION_CFG_REG : TYPEC_U_USB_WATER_PROTECTION_CFG_REG), 0); if (rc < 0) { smblib_err(chg, "Couldn't disable 1 percent CC_ID duty cycle rc=%d\n", Loading Loading @@ -1566,7 +1566,7 @@ static int smblib_dc_suspend_vote_callback(struct votable *votable, void *data, { struct smb_charger *chg = data; if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) return 0; /* resume input if suspend is invalid */ Loading Loading @@ -2166,7 +2166,7 @@ int smblib_get_prop_batt_iterm(struct smb_charger *chg, temp = buf[1] | (buf[0] << 8); temp = sign_extend32(temp, 15); if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) temp = DIV_ROUND_CLOSEST(temp * ITERM_LIMITS_PMI632_MA, ADC_CHG_ITERM_MASK); else Loading Loading @@ -2905,7 +2905,7 @@ int smblib_get_prop_dc_present(struct smb_charger *chg, int rc; u8 stat; if (chg->smb_version == PMI632_SUBTYPE) { if (chg->chg_param.smb_version == PMI632_SUBTYPE) { val->intval = 0; return 0; } Loading @@ -2926,7 +2926,7 @@ int smblib_get_prop_dc_online(struct smb_charger *chg, int rc = 0; u8 stat; if (chg->smb_version == PMI632_SUBTYPE) { if (chg->chg_param.smb_version == PMI632_SUBTYPE) { val->intval = 0; return 0; } Loading Loading @@ -3179,7 +3179,7 @@ int smblib_get_prop_usb_voltage_max_design(struct smb_charger *chg, /* else, fallthrough */ case POWER_SUPPLY_TYPE_USB_HVDCP_3: case POWER_SUPPLY_TYPE_USB_PD: if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) val->intval = MICRO_9V; else val->intval = MICRO_12V; Loading Loading @@ -3207,7 +3207,7 @@ int smblib_get_prop_usb_voltage_max(struct smb_charger *chg, } /* else, fallthrough */ case POWER_SUPPLY_TYPE_USB_HVDCP_3: if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) val->intval = MICRO_9V; else val->intval = MICRO_12V; Loading Loading @@ -3329,7 +3329,7 @@ int smblib_get_prop_usb_voltage_now(struct smb_charger *chg, * to occur randomly in the USBIN channel, particularly at high * voltages. */ if (chg->smb_version == PM8150B_SUBTYPE && pval.intval) if (chg->chg_param.smb_version == PM8150B_SUBTYPE && pval.intval) rc = smblib_read_mid_voltage_chan(chg, val); else rc = smblib_read_usbin_voltage_chan(chg, val); Loading Loading @@ -3699,7 +3699,7 @@ int smblib_get_prop_usb_current_now(struct smb_charger *chg, * For PMI632, scaling factor = reciprocal of * 0.4V/A in Buck mode, 0.8V/A in Boost mode. */ switch (chg->smb_version) { switch (chg->chg_param.smb_version) { case PMI632_SUBTYPE: buck_scale = 40; boost_scale = 80; Loading Loading @@ -4020,7 +4020,7 @@ int smblib_get_prop_connector_health(struct smb_charger *chg) * In PM8150B, SKIN channel measures Wireless charger receiver * temp, used to regulate DC ICL. */ if (chg->smb_version == PM8150B_SUBTYPE && dc_present) if (chg->chg_param.smb_version == PM8150B_SUBTYPE && dc_present) return smblib_get_skin_temp_status(chg); return POWER_SUPPLY_HEALTH_COOL; Loading Loading @@ -4989,7 +4989,7 @@ irqreturn_t usbin_uv_irq_handler(int irq, void *data) unsuspend_input: /* Force torch in boost mode to ensure it works with low ICL */ if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) schgm_flash_torch_priority(chg, TORCH_BOOST_MODE); if (chg->aicl_max_reached) { Loading Loading @@ -5253,7 +5253,7 @@ void smblib_usb_plugin_locked(struct smb_charger *chg) chg->aicl_cont_threshold_mv); chg->aicl_max_reached = false; if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) schgm_flash_torch_priority(chg, TORCH_BUCK_MODE); Loading Loading @@ -6830,7 +6830,7 @@ static void smblib_moisture_protection_work(struct work_struct *work) * Disable 1% duty cycle on CC_ID pin and enable uUSB factory mode * detection to track any change on RID, as interrupts are disable. */ rc = smblib_write(chg, ((chg->smb_version == PMI632_SUBTYPE) ? rc = smblib_write(chg, ((chg->chg_param.smb_version == PMI632_SUBTYPE) ? PMI632_TYPEC_U_USB_WATER_PROTECTION_CFG_REG : TYPEC_U_USB_WATER_PROTECTION_CFG_REG), 0); if (rc < 0) { Loading Loading @@ -7513,7 +7513,7 @@ int smblib_init(struct smb_charger *chg) switch (chg->mode) { case PARALLEL_MASTER: rc = qcom_batt_init(chg->smb_version); rc = qcom_batt_init(&chg->chg_param); if (rc < 0) { smblib_err(chg, "Couldn't init qcom_batt_init rc=%d\n", rc); Loading drivers/power/supply/qcom/smb5-lib.h +2 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ #include <linux/regulator/consumer.h> #include <linux/extcon-provider.h> #include "storm-watch.h" #include "battery.h" enum print_reason { PR_INTERRUPT = BIT(0), Loading Loading @@ -377,7 +378,6 @@ struct smb_charger { int pd_disabled; enum smb_mode mode; struct smb_chg_freq chg_freq; int smb_version; int otg_delay_ms; int weak_chg_icl_ua; bool pd_not_supported; Loading Loading @@ -459,6 +459,7 @@ struct smb_charger { struct alarm chg_termination_alarm; struct alarm dcin_aicl_alarm; struct charger_param chg_param; /* secondary charger config */ bool sec_pl_present; bool sec_cp_present; Loading Loading
drivers/power/supply/qcom/battery.c +24 −29 Original line number Diff line number Diff line Loading @@ -94,12 +94,11 @@ struct pl_data { struct class qcom_batt_class; struct wakeup_source *pl_ws; struct notifier_block nb; struct charger_param *chg_param; bool pl_disable; bool cp_disabled; int taper_entry_fv; int main_fcc_max; int fcc_step_size_ua; int fcc_step_delay_ms; /* debugfs directory */ struct dentry *dfs_root; u32 float_voltage_uv; Loading Loading @@ -523,8 +522,6 @@ ATTRIBUTE_GROUPS(batt_class); * FCC * **********/ #define EFFICIENCY_PCT 80 #define DEFAULT_FCC_STEP_SIZE_UA 100000 #define DEFAULT_FCC_STEP_UPDATE_DELAY_MS 1000 #define STEP_UP 1 #define STEP_DOWN -1 static void get_fcc_split(struct pl_data *chip, int total_ua, Loading Loading @@ -627,7 +624,7 @@ static void get_fcc_stepper_params(struct pl_data *chip, int main_fcc_ua, { int main_set_fcc_ua, total_fcc_ua; if (!chip->fcc_step_size_ua) { if (!chip->chg_param->fcc_step_size_ua) { pr_err("Invalid fcc stepper step size, value 0\n"); return; } Loading Loading @@ -658,16 +655,18 @@ static void get_fcc_stepper_params(struct pl_data *chip, int main_fcc_ua, chip->main_step_fcc_dir = (main_fcc_ua > chip->main_fcc_ua) ? STEP_UP : STEP_DOWN; chip->main_step_fcc_count = abs((main_fcc_ua - chip->main_fcc_ua) / chip->fcc_step_size_ua); chip->chg_param->fcc_step_size_ua); chip->main_step_fcc_residual = abs((main_fcc_ua - chip->main_fcc_ua) % chip->fcc_step_size_ua); chip->chg_param->fcc_step_size_ua); chip->parallel_step_fcc_dir = (parallel_fcc_ua > chip->slave_fcc_ua) ? STEP_UP : STEP_DOWN; chip->parallel_step_fcc_count = abs((parallel_fcc_ua - chip->slave_fcc_ua) / chip->fcc_step_size_ua); chip->parallel_step_fcc_residual = abs((parallel_fcc_ua - chip->slave_fcc_ua) % chip->fcc_step_size_ua); chip->parallel_step_fcc_count = abs((parallel_fcc_ua - chip->slave_fcc_ua) / chip->chg_param->fcc_step_size_ua); chip->parallel_step_fcc_residual = abs((parallel_fcc_ua - chip->slave_fcc_ua) % chip->chg_param->fcc_step_size_ua); skip_fcc_step_update: if (chip->parallel_step_fcc_count || chip->parallel_step_fcc_residual Loading Loading @@ -958,19 +957,20 @@ static void fcc_stepper_work(struct work_struct *work) } if (chip->main_step_fcc_count) { main_fcc += (chip->fcc_step_size_ua * chip->main_step_fcc_dir); main_fcc += (chip->chg_param->fcc_step_size_ua * chip->main_step_fcc_dir); chip->main_step_fcc_count--; reschedule_ms = chip->fcc_step_delay_ms; reschedule_ms = chip->chg_param->fcc_step_delay_ms; } else if (chip->main_step_fcc_residual) { main_fcc += chip->main_step_fcc_residual; chip->main_step_fcc_residual = 0; } if (chip->parallel_step_fcc_count) { parallel_fcc += (chip->fcc_step_size_ua * chip->parallel_step_fcc_dir); parallel_fcc += (chip->chg_param->fcc_step_size_ua * chip->parallel_step_fcc_dir); chip->parallel_step_fcc_count--; reschedule_ms = chip->fcc_step_delay_ms; reschedule_ms = chip->chg_param->fcc_step_delay_ms; } else if (chip->parallel_step_fcc_residual) { parallel_fcc += chip->parallel_step_fcc_residual; chip->parallel_step_fcc_residual = 0; Loading Loading @@ -1817,22 +1817,11 @@ static int pl_determine_initial_status(struct pl_data *chip) static void pl_config_init(struct pl_data *chip, int smb_version) { chip->fcc_step_size_ua = DEFAULT_FCC_STEP_SIZE_UA; chip->fcc_step_delay_ms = DEFAULT_FCC_STEP_UPDATE_DELAY_MS; switch (smb_version) { case PM8150B_SUBTYPE: chip->fcc_step_delay_ms = 100; break; case PMI8998_SUBTYPE: case PM660_SUBTYPE: chip->wa_flags = AICL_RERUN_WA_BIT | FORCE_INOV_DISABLE_BIT; break; case PMI632_SUBTYPE: break; case PM7250B_SUBTYPE: chip->fcc_step_delay_ms = 100; break; default: break; } Loading @@ -1857,11 +1846,16 @@ static void qcom_batt_create_debugfs(struct pl_data *chip) } #define DEFAULT_RESTRICTED_CURRENT_UA 1000000 int qcom_batt_init(int smb_version) int qcom_batt_init(struct charger_param *chg_param) { struct pl_data *chip; int rc = 0; if (!chg_param) { pr_err("invalid charger parameter\n"); return -EINVAL; } /* initialize just once */ if (the_chip) { pr_err("was initialized earlier. Failing now\n"); Loading @@ -1875,7 +1869,8 @@ int qcom_batt_init(int smb_version) qcom_batt_create_debugfs(chip); chip->slave_pct = 50; pl_config_init(chip, smb_version); chip->chg_param = chg_param; pl_config_init(chip, chg_param->smb_version); chip->restricted_current = DEFAULT_RESTRICTED_CURRENT_UA; chip->pl_ws = wakeup_source_register("qcom-battery"); Loading
drivers/power/supply/qcom/battery.h +9 −2 Original line number Diff line number Diff line /* SPDX-License-Identifier: GPL-2.0 */ /* * Copyright (c) 2017 The Linux Foundation. All rights reserved. * Copyright (c) 2017, 2019 The Linux Foundation. All rights reserved. */ #ifndef __BATTERY_H #define __BATTERY_H int qcom_batt_init(int smb_version); struct charger_param { u32 fcc_step_delay_ms; u32 fcc_step_size_ua; u32 smb_version; }; int qcom_batt_init(struct charger_param *param); void qcom_batt_deinit(void); #endif /* __BATTERY_H */
drivers/power/supply/qcom/qpnp-smb5.c +31 −16 Original line number Diff line number Diff line Loading @@ -325,20 +325,20 @@ static int smb5_chg_config_init(struct smb5 *chip) switch (pmic_rev_id->pmic_subtype) { case PM8150B_SUBTYPE: chip->chg.smb_version = PM8150B_SUBTYPE; chip->chg.chg_param.smb_version = PM8150B_SUBTYPE; chg->param = smb5_pm8150b_params; chg->name = "pm8150b_charger"; chg->wa_flags |= CHG_TERMINATION_WA; break; case PM7250B_SUBTYPE: chip->chg.smb_version = PM7250B_SUBTYPE; chip->chg.chg_param.smb_version = PM7250B_SUBTYPE; chg->param = smb5_pm8150b_params; chg->name = "pm7250b_charger"; chg->wa_flags |= CHG_TERMINATION_WA; chg->uusb_moisture_protection_capable = true; break; case PM6150_SUBTYPE: chip->chg.smb_version = PM6150_SUBTYPE; chip->chg.chg_param.smb_version = PM6150_SUBTYPE; chg->param = smb5_pm8150b_params; chg->name = "pm6150_charger"; chg->wa_flags |= SW_THERM_REGULATION_WA | CHG_TERMINATION_WA; Loading @@ -347,7 +347,7 @@ static int smb5_chg_config_init(struct smb5 *chip) chg->main_fcc_max = PM6150_MAX_FCC_UA; break; case PMI632_SUBTYPE: chip->chg.smb_version = PMI632_SUBTYPE; chip->chg.chg_param.smb_version = PMI632_SUBTYPE; chg->wa_flags |= WEAK_ADAPTER_WA | USBIN_OV_WA | CHG_TERMINATION_WA | USBIN_ADC_WA | SKIP_MISC_PBS_IRQ_WA; Loading Loading @@ -435,6 +435,8 @@ static int smb5_configure_internal_pull(struct smb_charger *chg, int type, #define OTG_DEFAULT_DEGLITCH_TIME_MS 50 #define DEFAULT_WD_BARK_TIME 64 #define DEFAULT_WD_SNARL_TIME_8S 0x07 #define DEFAULT_FCC_STEP_SIZE_UA 100000 #define DEFAULT_FCC_STEP_UPDATE_DELAY_MS 1000 static int smb5_parse_dt_misc(struct smb5 *chip, struct device_node *node) { int rc = 0, byte_len; Loading Loading @@ -571,6 +573,17 @@ static int smb5_parse_dt_misc(struct smb5 *chip, struct device_node *node) chip->dt.adc_based_aicl = of_property_read_bool(node, "qcom,adc-based-aicl"); of_property_read_u32(node, "qcom,fcc-step-delay-ms", &chg->chg_param.fcc_step_delay_ms); if (chg->chg_param.fcc_step_delay_ms <= 0) chg->chg_param.fcc_step_delay_ms = DEFAULT_FCC_STEP_UPDATE_DELAY_MS; of_property_read_u32(node, "qcom,fcc-step-size-ua", &chg->chg_param.fcc_step_size_ua); if (chg->chg_param.fcc_step_size_ua <= 0) chg->chg_param.fcc_step_size_ua = DEFAULT_FCC_STEP_SIZE_UA; return 0; } Loading Loading @@ -643,7 +656,8 @@ static int smb5_parse_dt_currents(struct smb5 *chip, struct device_node *node) rc = of_property_read_u32(node, "qcom,otg-cl-ua", &chg->otg_cl_ua); if (rc < 0) chg->otg_cl_ua = (chip->chg.smb_version == PMI632_SUBTYPE) ? chg->otg_cl_ua = (chip->chg.chg_param.smb_version == PMI632_SUBTYPE) ? MICRO_1PA : MICRO_3PA; rc = of_property_read_u32(node, "qcom,chg-term-src", Loading Loading @@ -1292,7 +1306,7 @@ static int smb5_usb_main_set_prop(struct power_supply *psy, rc = smblib_set_icl_current(chg, val->intval); break; case POWER_SUPPLY_PROP_FLASH_ACTIVE: if ((chg->smb_version == PMI632_SUBTYPE) if ((chg->chg_param.smb_version == PMI632_SUBTYPE) && (chg->flash_active != val->intval)) { chg->flash_active = val->intval; Loading Loading @@ -2057,7 +2071,7 @@ static int smb5_configure_typec(struct smb_charger *chg) return rc; } if (chg->smb_version != PMI632_SUBTYPE) { if (chg->chg_param.smb_version != PMI632_SUBTYPE) { rc = smblib_masked_write(chg, USBIN_LOAD_CFG_REG, USBIN_IN_COLLAPSE_GF_SEL_MASK | USBIN_AICL_STEP_TIMING_SEL_MASK, Loading Loading @@ -2118,7 +2132,8 @@ static int smb5_configure_micro_usb(struct smb_charger *chg) } /* Disable periodic monitoring of CC_ID pin */ rc = smblib_write(chg, ((chg->smb_version == PMI632_SUBTYPE) ? rc = smblib_write(chg, ((chg->chg_param.smb_version == PMI632_SUBTYPE) ? PMI632_TYPEC_U_USB_WATER_PROTECTION_CFG_REG : TYPEC_U_USB_WATER_PROTECTION_CFG_REG), 0); if (rc < 0) { Loading @@ -2144,7 +2159,7 @@ static int smb5_configure_iterm_thresholds_adc(struct smb5 *chip) s16 raw_hi_thresh, raw_lo_thresh, max_limit_ma; struct smb_charger *chg = &chip->chg; if (chip->chg.smb_version == PMI632_SUBTYPE) if (chip->chg.chg_param.smb_version == PMI632_SUBTYPE) max_limit_ma = ITERM_LIMITS_PMI632_MA; else max_limit_ma = ITERM_LIMITS_PM8150B_MA; Loading Loading @@ -2205,7 +2220,7 @@ static int smb5_configure_iterm_thresholds(struct smb5 *chip) switch (chip->dt.term_current_src) { case ITERM_SRC_ADC: if (chip->chg.smb_version == PM8150B_SUBTYPE) { if (chip->chg.chg_param.smb_version == PM8150B_SUBTYPE) { rc = smblib_masked_write(chg, CHGR_ADC_TERM_CFG_REG, TERM_BASED_ON_SYNC_CONV_OR_SAMPLE_CNT, TERM_BASED_ON_SAMPLE_CNT); Loading Loading @@ -2277,7 +2292,7 @@ static int smb5_init_dc_peripheral(struct smb_charger *chg) int rc = 0; /* PMI632 does not have DC peripheral */ if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) return 0; /* Set DCIN ICL to 100 mA */ Loading Loading @@ -2415,7 +2430,7 @@ static int smb5_init_connector_type(struct smb_charger *chg) * PMI632 can have the connector type defined by a dedicated register * PMI632_TYPEC_MICRO_USB_MODE_REG or by a common TYPEC_U_USB_CFG_REG. */ if (chg->smb_version == PMI632_SUBTYPE) { if (chg->chg_param.smb_version == PMI632_SUBTYPE) { rc = smblib_read(chg, PMI632_TYPEC_MICRO_USB_MODE_REG, &val); if (rc < 0) { dev_err(chg->dev, "Couldn't read USB mode rc=%d\n", rc); Loading Loading @@ -2460,7 +2475,7 @@ static int smb5_init_connector_type(struct smb_charger *chg) * boots with charger connected. * - Initialize flash module for PMI632 */ if (chg->smb_version == PMI632_SUBTYPE) { if (chg->chg_param.smb_version == PMI632_SUBTYPE) { schgm_flash_init(chg); smblib_rerun_apsd_if_required(chg); } Loading Loading @@ -3418,7 +3433,7 @@ static int smb5_probe(struct platform_device *pdev) } } switch (chg->smb_version) { switch (chg->chg_param.smb_version) { case PM8150B_SUBTYPE: case PM6150_SUBTYPE: case PM7250B_SUBTYPE: Loading
drivers/power/supply/qcom/smb5-lib.c +20 −20 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ #include <linux/ktime.h> #include "smb5-lib.h" #include "smb5-reg.h" #include "battery.h" #include "schgm-flash.h" #include "step-chg-jeita.h" #include "storm-watch.h" Loading Loading @@ -756,7 +755,7 @@ static int smblib_usb_pd_adapter_allowance_override(struct smb_charger *chg, { int rc = 0; if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) return 0; rc = smblib_write(chg, USBIN_ADAPTER_ALLOW_OVERRIDE_REG, Loading Loading @@ -803,7 +802,7 @@ static int smblib_set_usb_pd_allowed_voltage(struct smb_charger *chg, int rc, aicl_threshold; u8 vbus_allowance; if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) return 0; if (chg->pd_active == POWER_SUPPLY_PD_PPS_ACTIVE) { Loading Loading @@ -1484,8 +1483,8 @@ static int smblib_set_moisture_protection(struct smb_charger *chg, /* Set 1% duty cycle on ID detection */ rc = smblib_masked_write(chg, ((chg->smb_version == PMI632_SUBTYPE) ? PMI632_TYPEC_U_USB_WATER_PROTECTION_CFG_REG : ((chg->chg_param.smb_version == PMI632_SUBTYPE) ? PMI632_TYPEC_U_USB_WATER_PROTECTION_CFG_REG : TYPEC_U_USB_WATER_PROTECTION_CFG_REG), EN_MICRO_USB_WATER_PROTECTION_BIT | MICRO_USB_DETECTION_ON_TIME_CFG_MASK | Loading Loading @@ -1517,8 +1516,9 @@ static int smblib_set_moisture_protection(struct smb_charger *chg, } /* Disable periodic monitoring of CC_ID pin */ rc = smblib_write(chg, ((chg->smb_version == PMI632_SUBTYPE) ? PMI632_TYPEC_U_USB_WATER_PROTECTION_CFG_REG : rc = smblib_write(chg, ((chg->chg_param.smb_version == PMI632_SUBTYPE) ? PMI632_TYPEC_U_USB_WATER_PROTECTION_CFG_REG : TYPEC_U_USB_WATER_PROTECTION_CFG_REG), 0); if (rc < 0) { smblib_err(chg, "Couldn't disable 1 percent CC_ID duty cycle rc=%d\n", Loading Loading @@ -1566,7 +1566,7 @@ static int smblib_dc_suspend_vote_callback(struct votable *votable, void *data, { struct smb_charger *chg = data; if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) return 0; /* resume input if suspend is invalid */ Loading Loading @@ -2166,7 +2166,7 @@ int smblib_get_prop_batt_iterm(struct smb_charger *chg, temp = buf[1] | (buf[0] << 8); temp = sign_extend32(temp, 15); if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) temp = DIV_ROUND_CLOSEST(temp * ITERM_LIMITS_PMI632_MA, ADC_CHG_ITERM_MASK); else Loading Loading @@ -2905,7 +2905,7 @@ int smblib_get_prop_dc_present(struct smb_charger *chg, int rc; u8 stat; if (chg->smb_version == PMI632_SUBTYPE) { if (chg->chg_param.smb_version == PMI632_SUBTYPE) { val->intval = 0; return 0; } Loading @@ -2926,7 +2926,7 @@ int smblib_get_prop_dc_online(struct smb_charger *chg, int rc = 0; u8 stat; if (chg->smb_version == PMI632_SUBTYPE) { if (chg->chg_param.smb_version == PMI632_SUBTYPE) { val->intval = 0; return 0; } Loading Loading @@ -3179,7 +3179,7 @@ int smblib_get_prop_usb_voltage_max_design(struct smb_charger *chg, /* else, fallthrough */ case POWER_SUPPLY_TYPE_USB_HVDCP_3: case POWER_SUPPLY_TYPE_USB_PD: if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) val->intval = MICRO_9V; else val->intval = MICRO_12V; Loading Loading @@ -3207,7 +3207,7 @@ int smblib_get_prop_usb_voltage_max(struct smb_charger *chg, } /* else, fallthrough */ case POWER_SUPPLY_TYPE_USB_HVDCP_3: if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) val->intval = MICRO_9V; else val->intval = MICRO_12V; Loading Loading @@ -3329,7 +3329,7 @@ int smblib_get_prop_usb_voltage_now(struct smb_charger *chg, * to occur randomly in the USBIN channel, particularly at high * voltages. */ if (chg->smb_version == PM8150B_SUBTYPE && pval.intval) if (chg->chg_param.smb_version == PM8150B_SUBTYPE && pval.intval) rc = smblib_read_mid_voltage_chan(chg, val); else rc = smblib_read_usbin_voltage_chan(chg, val); Loading Loading @@ -3699,7 +3699,7 @@ int smblib_get_prop_usb_current_now(struct smb_charger *chg, * For PMI632, scaling factor = reciprocal of * 0.4V/A in Buck mode, 0.8V/A in Boost mode. */ switch (chg->smb_version) { switch (chg->chg_param.smb_version) { case PMI632_SUBTYPE: buck_scale = 40; boost_scale = 80; Loading Loading @@ -4020,7 +4020,7 @@ int smblib_get_prop_connector_health(struct smb_charger *chg) * In PM8150B, SKIN channel measures Wireless charger receiver * temp, used to regulate DC ICL. */ if (chg->smb_version == PM8150B_SUBTYPE && dc_present) if (chg->chg_param.smb_version == PM8150B_SUBTYPE && dc_present) return smblib_get_skin_temp_status(chg); return POWER_SUPPLY_HEALTH_COOL; Loading Loading @@ -4989,7 +4989,7 @@ irqreturn_t usbin_uv_irq_handler(int irq, void *data) unsuspend_input: /* Force torch in boost mode to ensure it works with low ICL */ if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) schgm_flash_torch_priority(chg, TORCH_BOOST_MODE); if (chg->aicl_max_reached) { Loading Loading @@ -5253,7 +5253,7 @@ void smblib_usb_plugin_locked(struct smb_charger *chg) chg->aicl_cont_threshold_mv); chg->aicl_max_reached = false; if (chg->smb_version == PMI632_SUBTYPE) if (chg->chg_param.smb_version == PMI632_SUBTYPE) schgm_flash_torch_priority(chg, TORCH_BUCK_MODE); Loading Loading @@ -6830,7 +6830,7 @@ static void smblib_moisture_protection_work(struct work_struct *work) * Disable 1% duty cycle on CC_ID pin and enable uUSB factory mode * detection to track any change on RID, as interrupts are disable. */ rc = smblib_write(chg, ((chg->smb_version == PMI632_SUBTYPE) ? rc = smblib_write(chg, ((chg->chg_param.smb_version == PMI632_SUBTYPE) ? PMI632_TYPEC_U_USB_WATER_PROTECTION_CFG_REG : TYPEC_U_USB_WATER_PROTECTION_CFG_REG), 0); if (rc < 0) { Loading Loading @@ -7513,7 +7513,7 @@ int smblib_init(struct smb_charger *chg) switch (chg->mode) { case PARALLEL_MASTER: rc = qcom_batt_init(chg->smb_version); rc = qcom_batt_init(&chg->chg_param); if (rc < 0) { smblib_err(chg, "Couldn't init qcom_batt_init rc=%d\n", rc); Loading
drivers/power/supply/qcom/smb5-lib.h +2 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ #include <linux/regulator/consumer.h> #include <linux/extcon-provider.h> #include "storm-watch.h" #include "battery.h" enum print_reason { PR_INTERRUPT = BIT(0), Loading Loading @@ -377,7 +378,6 @@ struct smb_charger { int pd_disabled; enum smb_mode mode; struct smb_chg_freq chg_freq; int smb_version; int otg_delay_ms; int weak_chg_icl_ua; bool pd_not_supported; Loading Loading @@ -459,6 +459,7 @@ struct smb_charger { struct alarm chg_termination_alarm; struct alarm dcin_aicl_alarm; struct charger_param chg_param; /* secondary charger config */ bool sec_pl_present; bool sec_cp_present; Loading