[PATCH v2 1/2] usb: typec: maxim_contaminant: disable low power mode when reading comparator values

Amit Sunil Dhamne via B4 Relay posted 2 patches 1 month, 2 weeks ago
[PATCH v2 1/2] usb: typec: maxim_contaminant: disable low power mode when reading comparator values
Posted by Amit Sunil Dhamne via B4 Relay 1 month, 2 weeks ago
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")
Cc: stable@vger.kernel.org
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
Re: [PATCH v2 1/2] usb: typec: maxim_contaminant: disable low power mode when reading comparator values
Posted by Heikki Krogerus 1 month, 2 weeks ago
On Fri, Aug 15, 2025 at 11:31:51AM -0700, Amit Sunil Dhamne via B4 Relay wrote:
> 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")
> Cc: stable@vger.kernel.org
> Signed-off-by: Amit Sunil Dhamne <amitsd@google.com>
> Reviewed-by: Badhri Jagan Sridharan <badhri@google.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.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
> 

-- 
heikki