From: Greg KH <gregkh@linuxfoundation.org>
To: amitsd@google.com
Cc: "Heikki Krogerus" <heikki.krogerus@linux.intel.com>,
"Badhri Jagan Sridharan" <badhri@google.com>,
"Guenter Roeck" <linux@roeck-us.net>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, "RD Babiera" <rdbabiera@google.com>,
"Kyle Tso" <kyletso@google.com>,
"André Draszik" <andre.draszik@linaro.org>,
"Peter Griffin" <peter.griffin@linaro.org>,
"Tudor Ambarus" <tudor.ambarus@linaro.org>
Subject: Re: [PATCH 2/2] usb: typec: maxim_contaminant: re-enable cc toggle if cc is open and port is clean
Date: Fri, 15 Aug 2025 07:31:16 +0200 [thread overview]
Message-ID: <2025081508-pasted-small-645f@gregkh> (raw)
In-Reply-To: <20250814-fix-upstream-contaminant-v1-2-801ce8089031@google.com>
On Thu, Aug 14, 2025 at 07:34:10PM -0700, Amit Sunil Dhamne via B4 Relay wrote:
> From: Amit Sunil Dhamne <amitsd@google.com>
>
> 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")
> Signed-off-by: Amit Sunil Dhamne <amitsd@google.com>
> Reviewed-by: Badhri Jagan Sridharan <badhri@google.com>
> ---
> drivers/usb/typec/tcpm/maxim_contaminant.c | 53 ++++++++++++++++++++++++++++++
> 1 file changed, 53 insertions(+)
>
> diff --git a/drivers/usb/typec/tcpm/maxim_contaminant.c b/drivers/usb/typec/tcpm/maxim_contaminant.c
> index 818cfe226ac7716de2fcbce205c67ea16acba592..af8da6dc60ae0bc5900f6614514d51f41eded8ab 100644
> --- a/drivers/usb/typec/tcpm/maxim_contaminant.c
> +++ b/drivers/usb/typec/tcpm/maxim_contaminant.c
> @@ -329,6 +329,39 @@ 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,
> + FIELD_PREP(CCLPMODESEL,
> + LOW_POWER_MODE_DISABLE));
> + 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 |
> + FIELD_PREP(TCPC_ROLE_CTRL_CC1,
> + TCPC_ROLE_CTRL_CC_RD) |
> + FIELD_PREP(TCPC_ROLE_CTRL_CC2,
> + TCPC_ROLE_CTRL_CC_RD));
> + 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,
> bool *cc_handled)
> {
> @@ -345,6 +378,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);
> @@ -377,6 +416,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);
> }
> } else if (chip->contaminant_state == DETECTED) {
> if (!(cc_status & TCPC_CC_STATUS_TOGGLING)) {
> @@ -384,6 +429,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.51.0.rc1.167.g924127e9c0-goog
>
>
<formletter>
This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>
prev parent reply other threads:[~2025-08-15 5:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-15 2:34 [PATCH 0/2] Fixes for maxim tcpc contaminant detection logic Amit Sunil Dhamne via B4 Relay
2025-08-15 2:34 ` [PATCH 1/2] usb: typec: maxim_contaminant: disable low power mode when reading comparator values Amit Sunil Dhamne via B4 Relay
2025-08-15 2:34 ` [PATCH 2/2] usb: typec: maxim_contaminant: re-enable cc toggle if cc is open and port is clean Amit Sunil Dhamne via B4 Relay
2025-08-15 5:31 ` Greg KH [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2025081508-pasted-small-645f@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=amitsd@google.com \
--cc=andre.draszik@linaro.org \
--cc=badhri@google.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=kyletso@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=peter.griffin@linaro.org \
--cc=rdbabiera@google.com \
--cc=stable@vger.kernel.org \
--cc=tudor.ambarus@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox