From a4f0de2f15657ed6fcf13eadc8cb6299aff362c4 Mon Sep 17 00:00:00 2001 From: Guocheng Wang Date: Wed, 27 Sep 2023 17:42:32 +0800 Subject: [PATCH] typec: Fix COM charging failed when using audio 2-1 adapter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using Type-C to 3.5mm Headphone 2-in-1 Adapter,COM charging Failed. Because the devices are in off-mode when usb plug-in,bootup process might cause some detection delay. So when DUT power on with typec and the typec vbus is exist,we need to wait some times for check type-c is connected before call smb5_typec_attach_detach_irq_handler. Change-Id: I8ea0e904bc493c13d666a09f81c34d33fdb2663f Signed-off-by: Guocheng Wang Reviewed-on: https://gerrit.mot.com/2752957 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Haijian Ma Reviewed-by: Huosheng Liao Submit-Approved: Jira Key --- drivers/power/supply/qcom/qpnp-smb5.c | 45 +++++++++++++++++++++++++++ drivers/power/supply/qcom/smb5-reg.h | 1 + 2 files changed, 46 insertions(+) diff --git a/drivers/power/supply/qcom/qpnp-smb5.c b/drivers/power/supply/qcom/qpnp-smb5.c index deccb443912c..824952c76a1c 100644 --- a/drivers/power/supply/qcom/qpnp-smb5.c +++ b/drivers/power/supply/qcom/qpnp-smb5.c @@ -2975,6 +2975,49 @@ static int smb5_init_typec_class(struct smb5 *chip) return rc; } +static int smb5_typec_cable_check(struct smb5 *chip) +{ + struct smb_charger *chg = &chip->chg; + int rc = 0; + int i = 0; + u8 stat = 0; + bool usb_input_present = false; + + if (chg->pd_not_supported) + return rc; + + rc = smblib_read(chg, USBIN_BASE + INT_RT_STS_OFFSET, &stat); + if (rc < 0) { + pr_err("%s Couldn't read USBIN_RT_STS rc=%d\n", __func__, rc); + return rc; + } + usb_input_present = stat & USBIN_PLUGIN_RT_STS_BIT; + + rc = smblib_read(chg, TYPE_C_MISC_STATUS_REG, &stat); + if (rc < 0) { + pr_err("%s Couldn't read TYPE_C_STATUS_4 rc=%d\n", __func__, rc); + return rc; + } + pr_info("%s usb_input_present=%d TYPE_C_STATUS_4=0x%02X\n", __func__, usb_input_present, stat); + + if (usb_input_present || (stat & TYPEC_VBUS_STATUS)) { + for (i = 0; i < 10; i++) { + rc = smblib_read(chg, TYPE_C_STATE_MACHINE_STATUS_REG, &stat); + if (rc < 0) { + pr_err("%s Couldn't read TYPE_C_STATE_MACHINE_STATUS rc=%d\n", __func__, rc); + return rc; + } + pr_info("%s index=%d stat=0x%02X\n", __func__, i, stat); + if (stat & TYPEC_ATTACH_DETACH_STATE_BIT) { + break; + } + msleep(50); + } + } + + return rc; +} + static int smb5_of_xlate(struct iio_dev *indio_dev, const struct of_phandle_args *iiospec) { @@ -3256,6 +3299,8 @@ static int smb5_probe(struct platform_device *pdev) goto cleanup; } + smb5_typec_cable_check(chip); + rc = smb5_determine_initial_status(chip); if (rc < 0) { pr_err("Couldn't determine initial status rc=%d\n", diff --git a/drivers/power/supply/qcom/smb5-reg.h b/drivers/power/supply/qcom/smb5-reg.h index 2f9976a659e4..6b58cfd65e76 100644 --- a/drivers/power/supply/qcom/smb5-reg.h +++ b/drivers/power/supply/qcom/smb5-reg.h @@ -359,6 +359,7 @@ enum { #define TYPE_C_MISC_STATUS_REG (TYPEC_BASE + 0x0B) #define TYPEC_WATER_DETECTION_STATUS_BIT BIT(7) #define SNK_SRC_MODE_BIT BIT(6) +#define TYPEC_VBUS_STATUS BIT(5) #define TYPEC_VBUS_ERROR_STATUS_BIT BIT(4) #define TYPEC_TCCDEBOUNCE_DONE_STATUS_BIT BIT(3) #define CC_ORIENTATION_BIT BIT(1)