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

Commit b0eb10d5 authored by Abhijeet Dharmapurikar's avatar Abhijeet Dharmapurikar
Browse files

smb-lib: wait before DRP for audio



The code currently switches to DRP immediately after a removal is
detected. This causes issues with audio since the mic bias remains enabled
and the user hears a pop noise.

Instead wait few milliseconds before switching to DRP, this way we allow
the audio driver to disable mic bias before switching to DRP.

Change-Id: Iec12bf5830b2aa487a475e10d795945064a346b1
Signed-off-by: default avatarAbhijeet Dharmapurikar <adharmap@codeaurora.org>
parent 5bc0e57c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -193,6 +193,11 @@ module_param_named(
	try_sink_enabled, __try_sink_enabled, int, 0600
);

static int __audio_headset_drp_wait_ms = 100;
module_param_named(
	audio_headset_drp_wait_ms, __audio_headset_drp_wait_ms, int, 0600
);

#define MICRO_1P5A		1500000
#define MICRO_P1A		100000
#define OTG_DEFAULT_DEGLITCH_TIME_MS	50
@@ -2260,6 +2265,7 @@ static int smb2_probe(struct platform_device *pdev)
	chg->irq_info = smb2_irqs;
	chg->die_health = -EINVAL;
	chg->name = "PMI";
	chg->audio_headset_drp_wait_ms = &__audio_headset_drp_wait_ms;

	chg->regmap = dev_get_regmap(chg->dev->parent, NULL);
	if (!chg->regmap) {
+29 −11
Original line number Diff line number Diff line
@@ -3815,6 +3815,20 @@ static int typec_try_sink(struct smb_charger *chg)
	bool debounce_done, vbus_detected, sink;
	u8 stat;
	int exit_mode = ATTACHED_SRC, rc;
	int typec_mode;

	if (!(*chg->try_sink_enabled))
		return ATTACHED_SRC;

	typec_mode = smblib_get_prop_typec_mode(chg);
	if (typec_mode == POWER_SUPPLY_TYPEC_SINK_AUDIO_ADAPTER
		|| typec_mode == POWER_SUPPLY_TYPEC_SINK_DEBUG_ACCESSORY)
		return ATTACHED_SRC;

	/*
	 * Try.SNK entry status - ATTACHWAIT.SRC state and detected Rd-open
	 * or RD-Ra for TccDebounce time.
	 */

	/* ignore typec interrupt while try.snk WIP */
	chg->try_sink_active = true;
@@ -3953,20 +3967,18 @@ static int typec_try_sink(struct smb_charger *chg)
static void typec_sink_insertion(struct smb_charger *chg)
{
	int exit_mode;
	int typec_mode;

	/*
	 * Try.SNK entry status - ATTACHWAIT.SRC state and detected Rd-open
	 * or RD-Ra for TccDebounce time.
	 */

	if (*chg->try_sink_enabled) {
	exit_mode = typec_try_sink(chg);

	if (exit_mode != ATTACHED_SRC) {
		smblib_usb_typec_change(chg);
		return;
	}
	}

	typec_mode = smblib_get_prop_typec_mode(chg);
	if (typec_mode == POWER_SUPPLY_TYPEC_SINK_AUDIO_ADAPTER)
		chg->is_audio_adapter = true;

	/* when a sink is inserted we should not wait on hvdcp timeout to
	 * enable pd
@@ -4091,6 +4103,12 @@ static void smblib_handle_typec_removal(struct smb_charger *chg)
		smblib_err(chg, "Couldn't set USBIN_ADAPTER_ALLOW_5V_OR_9V_TO_12V rc=%d\n",
			rc);

	if (chg->is_audio_adapter == true)
		/* wait for the audio driver to lower its en gpio */
		msleep(*chg->audio_headset_drp_wait_ms);

	chg->is_audio_adapter = false;

	/* enable DRP */
	rc = smblib_masked_write(chg, TYPE_C_INTRPT_ENB_SOFTWARE_CTRL_REG,
				 TYPEC_POWER_ROLE_CMD_MASK, 0);
+2 −0
Original line number Diff line number Diff line
@@ -239,6 +239,7 @@ struct smb_charger {
	struct smb_iio		iio;
	int			*debug_mask;
	int			*try_sink_enabled;
	int			*audio_headset_drp_wait_ms;
	enum smb_mode		mode;
	struct smb_chg_freq	chg_freq;
	int			smb_version;
@@ -345,6 +346,7 @@ struct smb_charger {
	u8			float_cfg;
	bool			use_extcon;
	bool			otg_present;
	bool			is_audio_adapter;

	/* workaround flag */
	u32			wa_flags;