* [PATCH v2] usb: typec: tcpm/tcpci_maxim: report BC1.2 current limit
@ 2026-12-04 11:00 André Draszik
2026-12-04 11:15 ` sashiko-bot
2026-12-04 14:00 ` Heikki Krogerus
0 siblings, 2 replies; 4+ messages in thread
From: André Draszik @ 2026-12-04 11:00 UTC (permalink / raw)
To: Badhri Jagan Sridharan, Heikki Krogerus, Greg Kroah-Hartman
Cc: Peter Griffin, Tudor Ambarus, Juan Yescas, Amit Sunil Dhamne,
kernel-team, linux-usb, André Draszik
Maxim TCPCI (MAX33359/MAX77759) ports attached to a non-PD source
advertising Rp-default always report a 500 mA current limit, even when
connected to a CDP or DCP source that can supply 1500 mA, and still
report 500 mA when no charging source is detected.
Commit 9d44cf247e7d ("usb: typec: tcpci_maxim: implement
get_current_limit") returns a hardcoded 500 mA workaround instead of
reading the hardware BC1.2 charger detection result in CHGTYP[1:0] of
vendor register BC_STATUS1 (0x87). On MAX77759, BC1.2 detection is
enabled by reset default (ChgDetEn in BC_CTRL1 0x8f resets to 1); on
Pixel 6 attached to a CDP host, BC_CTRL1 reads 0x81 and BC_STATUS1
reads 0x02 (CDP).
Replace the hardcoded 500 mA return in max_tcpci_get_current_limit()
with a read of TCPC_VENDOR_BC_STATUS1, returning 500 mA for SDP,
1500 mA for CDP and DCP, and 0 otherwise or on read error (matching the
tcpci_data::get_current_limit kerneldoc). Note that compared to the
hardcoded workaround, boards where firmware explicitly disables BC1.2
detection (or where detection has not completed yet) now receive 0 mA
instead of 500 mA.
Drop the broad workaround comment above max_tcpci_get_current_limit():
BC1.2 detection comes from the TCPC itself (as documented for
tcpc_dev::get_current_limit), not the USB stack, so only the SDP case
depends on USB enumeration. Keep a focused comment on CHGTYP_SDP and
return 500 mA (matching fusb302) because TCPM queries
get_current_limit() on entering SNK_DISCOVERY and SNK_READY and has no
conduit from the USB stack to report enumerated limits later.
Tested on Pixel 6 (MAX77759) with SDP (BC_STATUS1=0x01, 500 mA), CDP
(0x02, 1500 mA), and DCP (0x3b, 1500 mA) attach and hot-plug.
Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
Rebased onto gregkh-usb/usb-testing (d6ed2c3c5bb6) as a single patch
now that tcpci_data::get_current_limit and the initial tcpci_maxim
500 mA stub have landed there.
---
Changes in v2:
- Rebased onto gregkh-usb/usb-testing (d6ed2c3c5bb6).
- Dropped v1 patch 1/2 ("usb: typec: tcpci: add get_current_limit
callback"), superseded by commit 29bef51f3cf0 ("usb: typec: tcpci:
implement get_current_limit").
- Updated v1 patch 2/2 (now the sole patch) to replace the hardcoded
500 mA workaround added by commit 9d44cf247e7d ("usb: typec:
tcpci_maxim: implement get_current_limit") in place, keeping the
0 mA return on CHGTYP_NOT_ATTACHED or read error, and updated the
commit message accordingly.
- Dropped Heikki's Acked-by from v1 due to the changed baseline and
commit message.
- Link to v1: https://lore.kernel.org/r/20261125-tcpci-maxim-bc12-v1-0-656e01201efb@linaro.org
---
drivers/usb/typec/tcpm/tcpci_maxim.h | 8 +++++++
drivers/usb/typec/tcpm/tcpci_maxim_core.c | 36 +++++++++++++++++++++----------
2 files changed, 33 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/typec/tcpm/tcpci_maxim.h b/drivers/usb/typec/tcpm/tcpci_maxim.h
index b314606eb0f6..8290201f8ae3 100644
--- a/drivers/usb/typec/tcpm/tcpci_maxim.h
+++ b/drivers/usb/typec/tcpm/tcpci_maxim.h
@@ -10,6 +10,14 @@
#define VENDOR_CC_STATUS2 0x85
#define CC1_VUFP_RD0P5 BIT(1)
#define CC2_VUFP_RD0P5 BIT(5)
+
+#define TCPC_VENDOR_BC_STATUS1 0x87
+#define CHGTYP GENMASK(1, 0)
+#define CHGTYP_NOT_ATTACHED 0
+#define CHGTYP_SDP 1
+#define CHGTYP_CDP 2
+#define CHGTYP_DCP 3
+
#define TCPC_VENDOR_FLADC_STATUS 0x89
#define TCPC_VENDOR_CC_CTRL1 0x8c
diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c
index d6a4fce3c80d..6d966a6fc3cf 100644
--- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c
+++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c
@@ -5,6 +5,7 @@
* MAXIM TCPCI based TCPC driver
*/
+#include <linux/bitfield.h>
#include <linux/interrupt.h>
#include <linux/i2c.h>
#include <linux/kernel.h>
@@ -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;
+ }
}
static void max_tcpci_unregister_tcpci_port(void *tcpci)
---
base-commit: d6ed2c3c5bb60dc173b2edf38044695b6aefedd2
change-id: 20261125-tcpci-maxim-bc12-49a0ffb71d26
Best regards,
--
André Draszik <andre.draszik@linaro.org>
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2] usb: typec: tcpm/tcpci_maxim: report BC1.2 current limit
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
2026-12-04 13:14 ` André Draszik
2026-12-04 14:00 ` Heikki Krogerus
1 sibling, 1 reply; 4+ messages in thread
From: sashiko-bot @ 2026-12-04 11:15 UTC (permalink / raw)
To: André Draszik; +Cc: linux-usb
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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2] usb: typec: tcpm/tcpci_maxim: report BC1.2 current limit
2026-12-04 11:15 ` sashiko-bot
@ 2026-12-04 13:14 ` André Draszik
0 siblings, 0 replies; 4+ messages in thread
From: André Draszik @ 2026-12-04 13:14 UTC (permalink / raw)
To: sashiko-reviews; +Cc: linux-usb
On Fri, 2026-12-04 at 11:15 +0000, sashiko-bot@kernel.org wrote:
> [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?
>
> ...
>
> 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?
This is already addressed on the DT side for gs101-pixel-common.dtsi
(the only in-tree user of maxim,max33359 / maxim,max77759-tcpci) by:
arm64: dts: exynos: gs101-pixel-common: add BC1.2 completion time
https://patch.msgid.link/20261125-gs101-bc12-completion-time-v1-1-8fed7a3a7f43@linaro.org
That patch adds `sink-bc12-completion-time-ms = <500>;` so TCPM uses its
existing delayed transition before entering SNK_DISCOVERY rather than
sleeping inside get_current_limit() as fusb302.c doesn. It is already
queued in krzk/next/dt64 (commit 9fc107eb9860) and present in
linux-next (next-20261202) - it simply isn't in the usb-testing tree
yet.
Cheers,
Andre'
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] usb: typec: tcpm/tcpci_maxim: report BC1.2 current limit
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
@ 2026-12-04 14:00 ` Heikki Krogerus
1 sibling, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2026-12-04 14:00 UTC (permalink / raw)
To: André Draszik
Cc: Badhri Jagan Sridharan, Greg Kroah-Hartman, Peter Griffin,
Tudor Ambarus, Juan Yescas, Amit Sunil Dhamne, kernel-team,
linux-usb
On Fri, Dec 04, 2026 at 11:00:13AM +0000, André Draszik wrote:
> Maxim TCPCI (MAX33359/MAX77759) ports attached to a non-PD source
> advertising Rp-default always report a 500 mA current limit, even when
> connected to a CDP or DCP source that can supply 1500 mA, and still
> report 500 mA when no charging source is detected.
>
> Commit 9d44cf247e7d ("usb: typec: tcpci_maxim: implement
> get_current_limit") returns a hardcoded 500 mA workaround instead of
> reading the hardware BC1.2 charger detection result in CHGTYP[1:0] of
> vendor register BC_STATUS1 (0x87). On MAX77759, BC1.2 detection is
> enabled by reset default (ChgDetEn in BC_CTRL1 0x8f resets to 1); on
> Pixel 6 attached to a CDP host, BC_CTRL1 reads 0x81 and BC_STATUS1
> reads 0x02 (CDP).
>
> Replace the hardcoded 500 mA return in max_tcpci_get_current_limit()
> with a read of TCPC_VENDOR_BC_STATUS1, returning 500 mA for SDP,
> 1500 mA for CDP and DCP, and 0 otherwise or on read error (matching the
> tcpci_data::get_current_limit kerneldoc). Note that compared to the
> hardcoded workaround, boards where firmware explicitly disables BC1.2
> detection (or where detection has not completed yet) now receive 0 mA
> instead of 500 mA.
>
> Drop the broad workaround comment above max_tcpci_get_current_limit():
> BC1.2 detection comes from the TCPC itself (as documented for
> tcpc_dev::get_current_limit), not the USB stack, so only the SDP case
> depends on USB enumeration. Keep a focused comment on CHGTYP_SDP and
> return 500 mA (matching fusb302) because TCPM queries
> get_current_limit() on entering SNK_DISCOVERY and SNK_READY and has no
> conduit from the USB stack to report enumerated limits later.
>
> Tested on Pixel 6 (MAX77759) with SDP (BC_STATUS1=0x01, 500 mA), CDP
> (0x02, 1500 mA), and DCP (0x3b, 1500 mA) attach and hot-plug.
>
> Signed-off-by: André Draszik <andre.draszik@linaro.org>
Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> Rebased onto gregkh-usb/usb-testing (d6ed2c3c5bb6) as a single patch
> now that tcpci_data::get_current_limit and the initial tcpci_maxim
> 500 mA stub have landed there.
> ---
> Changes in v2:
> - Rebased onto gregkh-usb/usb-testing (d6ed2c3c5bb6).
> - Dropped v1 patch 1/2 ("usb: typec: tcpci: add get_current_limit
> callback"), superseded by commit 29bef51f3cf0 ("usb: typec: tcpci:
> implement get_current_limit").
> - Updated v1 patch 2/2 (now the sole patch) to replace the hardcoded
> 500 mA workaround added by commit 9d44cf247e7d ("usb: typec:
> tcpci_maxim: implement get_current_limit") in place, keeping the
> 0 mA return on CHGTYP_NOT_ATTACHED or read error, and updated the
> commit message accordingly.
> - Dropped Heikki's Acked-by from v1 due to the changed baseline and
> commit message.
> - Link to v1: https://lore.kernel.org/r/20261125-tcpci-maxim-bc12-v1-0-656e01201efb@linaro.org
> ---
> drivers/usb/typec/tcpm/tcpci_maxim.h | 8 +++++++
> drivers/usb/typec/tcpm/tcpci_maxim_core.c | 36 +++++++++++++++++++++----------
> 2 files changed, 33 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpci_maxim.h b/drivers/usb/typec/tcpm/tcpci_maxim.h
> index b314606eb0f6..8290201f8ae3 100644
> --- a/drivers/usb/typec/tcpm/tcpci_maxim.h
> +++ b/drivers/usb/typec/tcpm/tcpci_maxim.h
> @@ -10,6 +10,14 @@
> #define VENDOR_CC_STATUS2 0x85
> #define CC1_VUFP_RD0P5 BIT(1)
> #define CC2_VUFP_RD0P5 BIT(5)
> +
> +#define TCPC_VENDOR_BC_STATUS1 0x87
> +#define CHGTYP GENMASK(1, 0)
> +#define CHGTYP_NOT_ATTACHED 0
> +#define CHGTYP_SDP 1
> +#define CHGTYP_CDP 2
> +#define CHGTYP_DCP 3
> +
> #define TCPC_VENDOR_FLADC_STATUS 0x89
>
> #define TCPC_VENDOR_CC_CTRL1 0x8c
> diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c
> index d6a4fce3c80d..6d966a6fc3cf 100644
> --- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c
> +++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c
> @@ -5,6 +5,7 @@
> * MAXIM TCPCI based TCPC driver
> */
>
> +#include <linux/bitfield.h>
> #include <linux/interrupt.h>
> #include <linux/i2c.h>
> #include <linux/kernel.h>
> @@ -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;
> + }
> }
>
> static void max_tcpci_unregister_tcpci_port(void *tcpci)
>
> ---
> base-commit: d6ed2c3c5bb60dc173b2edf38044695b6aefedd2
> change-id: 20261125-tcpci-maxim-bc12-49a0ffb71d26
>
> Best regards,
> --
> André Draszik <andre.draszik@linaro.org>
>
--
heikki
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-04 14:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-12-04 13:14 ` André Draszik
2026-12-04 14:00 ` Heikki Krogerus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox