Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9F611A2545 for ; Sun, 24 Aug 2025 16:49:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756054196; cv=none; b=cF00xrPYc9MrFinhDb3n+czuyY1DjHY4ghcXxoJZBAD1+hzTexuf46CLieOafEv/TQCHtK1rXY96RNBv4BO8+eb9MGWCDmpHPYEpmkxDyDdv1saUz2plBCbmMhS9h30446uL29wO8B7djS1HA4yuGmfN+FbCns1fnFIF7AX+L0s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756054196; c=relaxed/simple; bh=XkrZq0oucVtthKASh7XWRn6lJSOt+RimcaKlDL2HqrM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GzJ+iPj37r50BVZam4ihUD2G+fHeNSEwVhM7eR4oHVKab7UH8/810eYVj8nm/anYuGakgVDxmnS6y0bSK5xJFVy8Wr+Zjk61SZUlHTHcdXukqpkrN0C35mdVLoURLqPkNBj3O4pE2Sz6QRmrnyEgtdeSEKgc7q29VaGRI+H8Yek= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aPeP/ioj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aPeP/ioj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEFAAC4CEEB; Sun, 24 Aug 2025 16:49:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1756054196; bh=XkrZq0oucVtthKASh7XWRn6lJSOt+RimcaKlDL2HqrM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aPeP/iojkvISYhkjuf4hqt41ngDLiulhEkXS+2pRhdKRU5BheCgmkrcX+4BndSZ/X I5Kbi1TdCeJt3YvB7SoXQesei90W/Lr/fjxqEfK3aCsRnNeLv3666xuOh9zzJUpAuj 4Z4jtEjcJiDcBfIkNI5gTru1MV2ovtbXX0J9Ym8+EHElvLSa7gir2vw22xidfYbYMF b5uFWJJlpoJ0k2lnWlsGvzAE7lN/KpmgaUUs3/vb3zglWFTEo4nzcf9/2sqWZqM00e vM/bebc6IAj6YWmXaBxjsD1TSNSnRjT96eInruIe99iNEh/E/yEc8mj+I0r7YwSGov 08DRQ07V0itCw== From: Sasha Levin To: stable@vger.kernel.org Cc: Amit Sunil Dhamne , stable , Badhri Jagan Sridharan , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 6.6.y] usb: typec: maxim_contaminant: re-enable cc toggle if cc is open and port is clean Date: Sun, 24 Aug 2025 12:49:53 -0400 Message-ID: <20250824164953.4152487-1-sashal@kernel.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <2025082346-facedown-granddad-9758@gregkh> References: <2025082346-facedown-granddad-9758@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Amit Sunil Dhamne [ Upstream commit a381c6d6f646226924809d0ad01a9465786da463 ] Presently in `max_contaminant_is_contaminant()` if there's no contaminant detected previously, CC is open & stopped toggling and no contaminant is currently present, TCPC.RC would be programmed to do DRP toggling. However, it didn't actively look for a connection. This would lead to Type-C not detect *any* new connections. Hence, in the above situation, re-enable toggling & program TCPC to look for a new connection. Also, return early if TCPC was looking for connection as this indicates TCPC has neither detected a potential connection nor a change in contaminant state. In addition, once dry detection is complete (port is dry), restart toggling. Fixes: 02b332a06397e ("usb: typec: maxim_contaminant: Implement check_contaminant callback") Cc: stable Signed-off-by: Amit Sunil Dhamne Reviewed-by: Badhri Jagan Sridharan Link: https://lore.kernel.org/r/20250815-fix-upstream-contaminant-v2-2-6c8d6c3adafb@google.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/typec/tcpm/maxim_contaminant.c | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/drivers/usb/typec/tcpm/maxim_contaminant.c b/drivers/usb/typec/tcpm/maxim_contaminant.c index 60f90272fed3..279dfc84d178 100644 --- a/drivers/usb/typec/tcpm/maxim_contaminant.c +++ b/drivers/usb/typec/tcpm/maxim_contaminant.c @@ -322,6 +322,34 @@ static int max_contaminant_enable_dry_detection(struct max_tcpci_chip *chip) return 0; } +static int max_contaminant_enable_toggling(struct max_tcpci_chip *chip) +{ + struct regmap *regmap = chip->data.regmap; + int ret; + + /* Disable dry detection if enabled. */ + ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCLPMODESEL_MASK, + ULTRA_LOW_POWER_MODE); + if (ret) + return ret; + + ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL1, CCCONNDRY, 0); + if (ret) + return ret; + + ret = max_tcpci_write8(chip, TCPC_ROLE_CTRL, TCPC_ROLE_CTRL_DRP | 0xA); + if (ret) + return ret; + + ret = regmap_update_bits(regmap, TCPC_TCPC_CTRL, + TCPC_TCPC_CTRL_EN_LK4CONN_ALRT, + TCPC_TCPC_CTRL_EN_LK4CONN_ALRT); + if (ret) + return ret; + + return max_tcpci_write8(chip, TCPC_COMMAND, TCPC_CMD_LOOK4CONNECTION); +} + bool max_contaminant_is_contaminant(struct max_tcpci_chip *chip, bool disconnect_while_debounce) { u8 cc_status, pwr_cntl; @@ -335,6 +363,12 @@ bool max_contaminant_is_contaminant(struct max_tcpci_chip *chip, bool disconnect if (ret < 0) return false; + if (cc_status & TCPC_CC_STATUS_TOGGLING) { + if (chip->contaminant_state == DETECTED) + return true; + return false; + } + if (chip->contaminant_state == NOT_DETECTED || chip->contaminant_state == SINK) { if (!disconnect_while_debounce) msleep(100); @@ -367,6 +401,12 @@ bool max_contaminant_is_contaminant(struct max_tcpci_chip *chip, bool disconnect max_contaminant_enable_dry_detection(chip); return true; } + + ret = max_contaminant_enable_toggling(chip); + if (ret) + dev_err(chip->dev, + "Failed to enable toggling, ret=%d", + ret); } return false; } else if (chip->contaminant_state == DETECTED) { @@ -375,6 +415,14 @@ bool max_contaminant_is_contaminant(struct max_tcpci_chip *chip, bool disconnect if (chip->contaminant_state == DETECTED) { max_contaminant_enable_dry_detection(chip); return true; + } else { + ret = max_contaminant_enable_toggling(chip); + if (ret) { + dev_err(chip->dev, + "Failed to enable toggling, ret=%d", + ret); + return true; + } } } } -- 2.50.1