Linux USB
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "André Draszik" <andre.draszik@linaro.org>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v2] usb: typec: tcpm/tcpci_maxim: report BC1.2 current limit
Date: Fri, 04 Dec 2026 11:15:19 +0000	[thread overview]
Message-ID: <sashiko-outbox-249664@kernel.org> (raw)
In-Reply-To: <20261204-tcpci-maxim-bc12-v2-1-3c8ccacc9bdd@linaro.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] usb: typec: tcpci_maxim: BC1.2 race can permanently latch 0
  mA limit
--

commit b1be9133e1f16e25c6fc3ce85af91dbc2bae9bd1
Author: André Draszik <andre.draszik@linaro.org>

usb: typec: tcpm/tcpci_maxim: report BC1.2 current limit

This commit replaces the hardcoded 500 mA return in
max_tcpci_get_current_limit() with a read of TCPC_VENDOR_BC_STATUS1 to
report 500 mA for SDP, 1500 mA for CDP/DCP, and 0 mA otherwise.

> diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c
> index d6a4fce3c80df..6d966a6fc3cf6 100644
> --- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c
> +++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c

[ ... ]

> @@ -485,18 +486,31 @@ static bool max_tcpci_attempt_vconn_swap_discovery(struct tcpci *tcpci, struct t
>  	return true;
>  }
>  
> -/*
> - * This callback is used by the TCPM to determine the current limit to set when
> - * Rp-def is advertised on the CC pins. The actual current limit comes from
> - * other subsystems such as the USB gadget/host stack (USB 2.0/USB 3.2) and
> - * BC1.2. As a workaround, report the USB 2.0 current limit of 500 mA to enable
> - * charging when the device is connected to a non-PD source advertising Rp-def.
> - * This can be removed once a mechanism for the USB core to communicate the
> - * current limit to this driver is implemented.
> - */
> -static int max_tcpci_get_current_limit(struct tcpci *tcpci, struct tcpci_data *tdata)
> +static int max_tcpci_get_current_limit(struct tcpci *tcpci,
> +				       struct tcpci_data *tdata)
>  {
> -	return 500;
> +	struct max_tcpci_chip *chip = tdata_to_max_tcpci(tdata);
> +	u8 status;
> +	int ret;
> +
> +	/* Returns 0 if BC1.2 detection is disabled or has not finished yet. */
> +	ret = max_tcpci_read8(chip, TCPC_VENDOR_BC_STATUS1, &status);
> +	if (ret < 0)
> +		return 0;
> +
> +	switch (FIELD_GET(CHGTYP, status)) {
> +	case CHGTYP_SDP:
> +		/*
> +		 * Assume a configured USB 2.0 device until the USB stack can
> +		 * report enumerated SDP limits to TCPM.
> +		 */
> +		return 500;
> +	case CHGTYP_CDP:
> +	case CHGTYP_DCP:
> +		return 1500;
> +	default:
> +		return 0;
> +	}
>  }

[Severity: Medium]
Can this single read of TCPC_VENDOR_BC_STATUS1 permanently latch a 0 mA
current limit when BC1.2 detection is still in progress?

gs101-pixel-common.dtsi omits sink-bc12-completion-time-ms (defaulting to
0 ms, while the maxim,max33359 binding budgets 500 ms) and sets pd-disable.
TCPM then queries get_current_limit() in SNK_DISCOVERY and SNK_READY right
after the 200 ms CC debounce.

Once in SNK_READY, TCPM never re-queries get_current_limit() unless CC
changes, and max_tcpci_init_regs() does not unmask vendor BC1.2 alerts.
If BC1.2 finishes after that read, TCPM latches 0 mA for the whole attach
session.

max77759_charger's psy_work_item() then sees a 0 mA limit and sets
MAX77759_CHGR_MODE_OFF, leaving charging disabled until unplug and replug.
This is a regression from the 500 mA return in 9d44cf247e7d ("usb: typec:
tcpci_maxim: implement get_current_limit").

Could max_tcpci_get_current_limit() poll TCPC_VENDOR_BC_STATUS1 with a
timeout until detection completes, as tcpm_get_current_limit() in
fusb302.c does?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-tcpci-maxim-bc12-v2-1-3c8ccacc9bdd@linaro.org?part=1

  reply	other threads:[~2026-12-04 11:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 11:00 [PATCH v2] usb: typec: tcpm/tcpci_maxim: report BC1.2 current limit André Draszik
2026-12-04 11:15 ` sashiko-bot [this message]
2026-12-04 13:14   ` André Draszik
2026-12-04 14:00 ` Heikki Krogerus

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=sashiko-outbox-249664@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=andre.draszik@linaro.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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