Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d89ff1ff authored by Harry Yang's avatar Harry Yang
Browse files

qcom-charger: set optimal boost switching frequency



Currently, the default boost switching frequency is fixed at 800KHz,
which shows low efficiency in low USB load.

To improve it, only use the default 800KHz when boost current goes
above 100mA; otherwise, switch to 2MHz.

CRs-Fixed: 1095917
Change-Id: Iebb62303febfb78738ada4553fdb9b9eb4810ed5
Signed-off-by: default avatarHarry Yang <harryy@codeaurora.org>
parent 8204f697
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -64,6 +64,12 @@ Charger specific properties:
  Value type: <u32>
  Definition: Specifies the DC input current limit in micro-amps.

- qcom,boost-threshold-ua
  Usage:      optional
  Value type: <u32>
  Definition: Specifies the boost current threshold in micro-amps.
		If the value is not present, 100mA is used as default.

- qcom,wipower-max-uw
  Usage:      optional
  Value type: <u32>
+23 −0
Original line number Diff line number Diff line
@@ -210,6 +210,13 @@ static struct smb_params v1_params = {
		.max_u	= 2000,
		.step_u	= 200,
	},
	.freq_boost		= {
		.name	= "boost switching frequency",
		.reg	= CFG_BUCKBOOST_FREQ_SELECT_BOOST_REG,
		.min_u	= 600,
		.max_u	= 2000,
		.step_u	= 200,
	},
};

#define STEP_CHARGING_MAX_STEPS	5
@@ -218,6 +225,7 @@ struct smb_dt_props {
	int	usb_icl_ua;
	int	otg_cl_ua;
	int	dc_icl_ua;
	int	boost_threshold_ua;
	int	fv_uv;
	int	wipower_max_uw;
	u32	step_soc_threshold[STEP_CHARGING_MAX_STEPS - 1];
@@ -243,6 +251,7 @@ module_param_named(
);

#define MICRO_1P5A	1500000
#define MICRO_P1A	100000
static int smb2_parse_dt(struct smb2 *chip)
{
	struct smb_charger *chg = &chip->chg;
@@ -304,6 +313,12 @@ static int smb2_parse_dt(struct smb2 *chip)
	if (rc < 0)
		chip->dt.dc_icl_ua = -EINVAL;

	rc = of_property_read_u32(node,
				"qcom,boost-threshold-ua",
				&chip->dt.boost_threshold_ua);
	if (rc < 0)
		chip->dt.boost_threshold_ua = MICRO_P1A;

	rc = of_property_read_u32(node, "qcom,wipower-max-uw",
				&chip->dt.wipower_max_uw);
	if (rc < 0)
@@ -370,6 +385,7 @@ static enum power_supply_property smb2_usb_props[] = {
	POWER_SUPPLY_PROP_PD_ACTIVE,
	POWER_SUPPLY_PROP_INPUT_CURRENT_SETTLED,
	POWER_SUPPLY_PROP_INPUT_CURRENT_NOW,
	POWER_SUPPLY_PROP_BOOST_CURRENT,
	POWER_SUPPLY_PROP_PE_START,
};

@@ -436,6 +452,9 @@ static int smb2_usb_get_prop(struct power_supply *psy,
	case POWER_SUPPLY_PROP_INPUT_CURRENT_NOW:
		rc = smblib_get_prop_usb_current_now(chg, val);
		break;
	case POWER_SUPPLY_PROP_BOOST_CURRENT:
		val->intval = chg->boost_current_ua;
		break;
	case POWER_SUPPLY_PROP_PD_IN_HARD_RESET:
		rc = smblib_get_prop_pd_in_hard_reset(chg, val);
		break;
@@ -490,6 +509,9 @@ static int smb2_usb_set_prop(struct power_supply *psy,
	case POWER_SUPPLY_PROP_PD_USB_SUSPEND_SUPPORTED:
		chg->system_suspend_supported = val->intval;
		break;
	case POWER_SUPPLY_PROP_BOOST_CURRENT:
		rc = smblib_set_prop_boost_current(chg, val);
		break;
	default:
		pr_err("set prop %d is not supported\n", psp);
		rc = -EINVAL;
@@ -1073,6 +1095,7 @@ static int smb2_init_hw(struct smb2 *chip)

	chg->otg_cl_ua = chip->dt.otg_cl_ua;
	chg->dcp_icl_ua = chip->dt.usb_icl_ua;
	chg->boost_threshold_ua = chip->dt.boost_threshold_ua;

	rc = smblib_read(chg, APSD_RESULT_STATUS_REG, &stat);
	if (rc < 0) {
+28 −1
Original line number Diff line number Diff line
@@ -1501,7 +1501,7 @@ int smblib_get_prop_dc_current_max(struct smb_charger *chg,
}

/*******************
 * USB PSY SETTERS *
 * DC PSY SETTERS *
 * *****************/

int smblib_set_prop_dc_current_max(struct smb_charger *chg,
@@ -1883,6 +1883,25 @@ int smblib_set_prop_usb_current_max(struct smb_charger *chg,
	return rc;
}

#define FSW_2MHZ		2000
#define FSW_800KHZ_RESET	800
int smblib_set_prop_boost_current(struct smb_charger *chg,
				    const union power_supply_propval *val)
{
	int rc = 0;

	rc = smblib_set_charge_param(chg, &chg->param.freq_boost,
				val->intval <= chg->boost_threshold_ua ?
				FSW_2MHZ : FSW_800KHZ_RESET);
	if (rc < 0) {
		dev_err(chg->dev, "Error in setting freq_boost rc=%d\n", rc);
		return rc;
	}

	chg->boost_current_ua = val->intval;
	return rc;
}

int smblib_set_prop_typec_power_role(struct smb_charger *chg,
				     const union power_supply_propval *val)
{
@@ -2753,6 +2772,12 @@ static void typec_sink_insertion(struct smb_charger *chg)
			false, 0);
}

static void typec_sink_removal(struct smb_charger *chg)
{
	smblib_set_charge_param(chg, &chg->param.freq_boost, FSW_800KHZ_RESET);
	chg->boost_current_ua = 0;
}

static void smblib_handle_typec_removal(struct smb_charger *chg)
{
	vote(chg->pd_disallowed_votable_indirect, CC_DETACHED_VOTER, true, 0);
@@ -2772,6 +2797,7 @@ static void smblib_handle_typec_removal(struct smb_charger *chg)
	vote(chg->apsd_disable_votable, PD_HARD_RESET_VOTER, false, 0);

	typec_source_removal(chg);
	typec_sink_removal(chg);

	smblib_update_usb_type(chg);
}
@@ -2789,6 +2815,7 @@ static void smblib_handle_typec_insertion(struct smb_charger *chg,
		typec_sink_insertion(chg);
	} else {
		typec_source_insertion(chg);
		typec_sink_removal(chg);
	}

	vote(chg->pd_disallowed_votable_indirect, LEGACY_CABLE_VOTER,
+5 −0
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ struct smb_params {
	struct smb_chg_param	step_soc;
	struct smb_chg_param	step_cc_delta[5];
	struct smb_chg_param	freq_buck;
	struct smb_chg_param	freq_boost;
};

struct parallel_params {
@@ -198,6 +199,7 @@ struct smb_charger {
	int			voltage_max_uv;
	int			pd_active;
	bool			system_suspend_supported;
	int			boost_threshold_ua;

	int			system_temp_level;
	int			thermal_levels;
@@ -216,6 +218,7 @@ struct smb_charger {
	/* workaround flag */
	u32			wa_flags;
	enum cc2_sink_type	cc2_sink_detach_flag;
	int			boost_current_ua;
};

int smblib_read(struct smb_charger *chg, u16 addr, u8 *val);
@@ -347,6 +350,8 @@ int smblib_set_prop_usb_voltage_min(struct smb_charger *chg,
				const union power_supply_propval *val);
int smblib_set_prop_usb_voltage_max(struct smb_charger *chg,
				const union power_supply_propval *val);
int smblib_set_prop_boost_current(struct smb_charger *chg,
				const union power_supply_propval *val);
int smblib_set_prop_typec_power_role(struct smb_charger *chg,
				const union power_supply_propval *val);
int smblib_set_prop_pd_active(struct smb_charger *chg,
+1 −0
Original line number Diff line number Diff line
@@ -1000,5 +1000,6 @@ enum {
#define SYSOK_OPTIONS_MASK			GENMASK(2, 0)

#define CFG_BUCKBOOST_FREQ_SELECT_BUCK_REG	(MISC_BASE + 0xA0)
#define CFG_BUCKBOOST_FREQ_SELECT_BOOST_REG	(MISC_BASE + 0xA1)

#endif /* __SMB2_CHARGER_REG_H */