Merge "smb-lib: wait before DRP for audio"
diff --git a/drivers/power/supply/qcom/qpnp-smb2.c b/drivers/power/supply/qcom/qpnp-smb2.c
index ea78ddd3..8536a61 100644
--- a/drivers/power/supply/qcom/qpnp-smb2.c
+++ b/drivers/power/supply/qcom/qpnp-smb2.c
@@ -193,6 +193,11 @@
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
@@ -2272,6 +2277,7 @@
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) {
diff --git a/drivers/power/supply/qcom/smb-lib.c b/drivers/power/supply/qcom/smb-lib.c
index b4eef54..bca4be3 100644
--- a/drivers/power/supply/qcom/smb-lib.c
+++ b/drivers/power/supply/qcom/smb-lib.c
@@ -3829,6 +3829,20 @@
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;
@@ -3967,21 +3981,19 @@
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.
- */
+ exit_mode = typec_try_sink(chg);
- if (*chg->try_sink_enabled) {
- exit_mode = typec_try_sink(chg);
-
- if (exit_mode != ATTACHED_SRC) {
- smblib_usb_typec_change(chg);
- return;
- }
+ 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
*/
@@ -4105,6 +4117,12 @@
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);
diff --git a/drivers/power/supply/qcom/smb-lib.h b/drivers/power/supply/qcom/smb-lib.h
index 351a0e9..1154b09 100644
--- a/drivers/power/supply/qcom/smb-lib.h
+++ b/drivers/power/supply/qcom/smb-lib.h
@@ -239,6 +239,7 @@
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 @@
u8 float_cfg;
bool use_extcon;
bool otg_present;
+ bool is_audio_adapter;
/* workaround flag */
u32 wa_flags;