stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Fixes for maxim tcpc contaminant detection logic
@ 2025-08-15  2:34 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
  0 siblings, 2 replies; 5+ messages in thread
From: Amit Sunil Dhamne via B4 Relay @ 2025-08-15  2:34 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman, Badhri Jagan Sridharan,
	Guenter Roeck
  Cc: linux-usb, linux-kernel, stable, RD Babiera, Kyle Tso,
	André Draszik, Peter Griffin, Tudor Ambarus,
	Amit Sunil Dhamne

Add fixes to the CC contaminant/connection detection logic to improve
reliability and stability of the maxim tcpc driver.

---
Amit Sunil Dhamne (2):
      usb: typec: maxim_contaminant: disable low power mode when reading comparator values
      usb: typec: maxim_contaminant: re-enable cc toggle if cc is open and port is clean

 drivers/usb/typec/tcpm/maxim_contaminant.c | 58 ++++++++++++++++++++++++++++++
 drivers/usb/typec/tcpm/tcpci_maxim.h       |  1 +
 2 files changed, 59 insertions(+)
---
base-commit: 89be9a83ccf1f88522317ce02f854f30d6115c41
change-id: 20250802-fix-upstream-contaminant-16910e2762ca

Best regards,
-- 
Amit Sunil Dhamne <amitsd@google.com>



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] usb: typec: maxim_contaminant: disable low power mode when reading comparator values
  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 ` Amit Sunil Dhamne via B4 Relay
  2025-08-15  2:42   ` kernel test robot
  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
  1 sibling, 1 reply; 5+ messages in thread
From: Amit Sunil Dhamne via B4 Relay @ 2025-08-15  2:34 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman, Badhri Jagan Sridharan,
	Guenter Roeck
  Cc: linux-usb, linux-kernel, stable, RD Babiera, Kyle Tso,
	André Draszik, Peter Griffin, Tudor Ambarus,
	Amit Sunil Dhamne

From: Amit Sunil Dhamne <amitsd@google.com>

Low power mode is enabled when reading CC resistance as part of
`max_contaminant_read_resistance_kohm()` and left in that state.
However, it's supposed to work with 1uA current source. To read CC
comparator values current source is changed to 80uA. This causes a storm
of CC interrupts as it (falsely) detects a potential contaminant. To
prevent this, disable low power mode current sourcing before reading
comparator values.

Fixes: 02b332a06397 ("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 | 5 +++++
 drivers/usb/typec/tcpm/tcpci_maxim.h       | 1 +
 2 files changed, 6 insertions(+)

diff --git a/drivers/usb/typec/tcpm/maxim_contaminant.c b/drivers/usb/typec/tcpm/maxim_contaminant.c
index 0cdda06592fd3cc34e2179ccd49ef677f8ec9792..818cfe226ac7716de2fcbce205c67ea16acba592 100644
--- a/drivers/usb/typec/tcpm/maxim_contaminant.c
+++ b/drivers/usb/typec/tcpm/maxim_contaminant.c
@@ -188,6 +188,11 @@ static int max_contaminant_read_comparators(struct max_tcpci_chip *chip, u8 *ven
 	if (ret < 0)
 		return ret;
 
+	/* Disable low power mode */
+	ret = regmap_update_bits(regmap, TCPC_VENDOR_CC_CTRL2, CCLPMODESEL,
+				 FIELD_PREP(CCLPMODESEL,
+					    LOW_POWER_MODE_DISABLE));
+
 	/* Sleep to allow comparators settle */
 	usleep_range(5000, 6000);
 	ret = regmap_update_bits(regmap, TCPC_TCPC_CTRL, TCPC_TCPC_CTRL_ORIENTATION, PLUG_ORNT_CC1);
diff --git a/drivers/usb/typec/tcpm/tcpci_maxim.h b/drivers/usb/typec/tcpm/tcpci_maxim.h
index 76270d5c283880dc49b13cabe7d682f2c2bf15fe..b33540a42a953dc6d8197790ee4af3b6f52791ce 100644
--- a/drivers/usb/typec/tcpm/tcpci_maxim.h
+++ b/drivers/usb/typec/tcpm/tcpci_maxim.h
@@ -21,6 +21,7 @@
 #define CCOVPDIS                                BIT(6)
 #define SBURPCTRL                               BIT(5)
 #define CCLPMODESEL                             GENMASK(4, 3)
+#define LOW_POWER_MODE_DISABLE                  0
 #define ULTRA_LOW_POWER_MODE                    1
 #define CCRPCTRL                                GENMASK(2, 0)
 #define UA_1_SRC                                1

-- 
2.51.0.rc1.167.g924127e9c0-goog



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] usb: typec: maxim_contaminant: re-enable cc toggle if cc is open and port is clean
  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 ` Amit Sunil Dhamne via B4 Relay
  2025-08-15  5:31   ` Greg KH
  1 sibling, 1 reply; 5+ messages in thread
From: Amit Sunil Dhamne via B4 Relay @ 2025-08-15  2:34 UTC (permalink / raw)
  To: Heikki Krogerus, Greg Kroah-Hartman, Badhri Jagan Sridharan,
	Guenter Roeck
  Cc: linux-usb, linux-kernel, stable, RD Babiera, Kyle Tso,
	André Draszik, Peter Griffin, Tudor Ambarus,
	Amit Sunil Dhamne

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



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] usb: typec: maxim_contaminant: disable low power mode when reading comparator values
  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:42   ` kernel test robot
  0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2025-08-15  2:42 UTC (permalink / raw)
  To: Amit Sunil Dhamne via B4 Relay; +Cc: stable, oe-kbuild-all

Hi,

Thanks for your patch.

FYI: kernel test robot notices the stable kernel rule is not satisfied.

The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-1

Rule: add the tag "Cc: stable@vger.kernel.org" in the sign-off area to have the patch automatically included in the stable tree.
Subject: [PATCH 1/2] usb: typec: maxim_contaminant: disable low power mode when reading comparator values
Link: https://lore.kernel.org/stable/20250814-fix-upstream-contaminant-v1-1-801ce8089031%40google.com

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] usb: typec: maxim_contaminant: re-enable cc toggle if cc is open and port is clean
  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
  0 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2025-08-15  5:31 UTC (permalink / raw)
  To: amitsd
  Cc: Heikki Krogerus, Badhri Jagan Sridharan, Guenter Roeck, linux-usb,
	linux-kernel, stable, RD Babiera, Kyle Tso, André Draszik,
	Peter Griffin, Tudor Ambarus

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>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-08-15  5:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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:42   ` kernel test robot
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).