Linux USB
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: "André Draszik" <andre.draszik@linaro.org>
Cc: Badhri Jagan Sridharan <badhri@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Peter Griffin <peter.griffin@linaro.org>,
	Tudor Ambarus <tudor.ambarus@linaro.org>,
	Juan Yescas <jyescas@google.com>,
	Amit Sunil Dhamne <amitsd@google.com>,
	kernel-team@android.com, linux-usb@vger.kernel.org
Subject: Re: [PATCH 2/2] usb: typec: tcpm/tcpci_maxim: report BC1.2 current limit
Date: Mon, 30 Nov 2026 14:03:35 +0100	[thread overview]
Message-ID: <aw10J7J8mnkGMbOx@black.igk.intel.com> (raw)
In-Reply-To: <20261125-tcpci-maxim-bc12-v1-2-656e01201efb@linaro.org>

On Wed, Nov 25, 2026 at 02:04:12PM +0000, André Draszik wrote:
> Maxim TCPCI (MAX33359/MAX77759) ports attached to a non-PD source
> advertising Rp-default report a 0 mA current limit, so charger drivers
> such as max77759-charger disable charging even when hardware BC1.2
> detection has identified a charging port.
> 
> For TYPEC_CC_RP_DEF, tcpm_get_current_limit() returns 0 mA unless the
> TCPC reports a limit. The Maxim TCPC exposes its BC1.2 charger detection
> result in CHGTYP[1:0] of vendor register BC_STATUS1 (0x87), which
> tcpci_maxim does not read; on Pixel 6 (MAX77759) attached to a CDP host,
> BC_STATUS1 reads 0x02 (CDP) with BC_CTRL1 (0x8f) reading 0x81
> (CHGDETEN set).
> 
> Implement the new tcpci_data get_current_limit callback to read
> BC_STATUS1 and return 500 mA for SDP and 1500 mA for CDP/DCP (and 0
> otherwise or on read error). Return 500 mA for SDP (matching fusb302)
> because TCPM queries get_current_limit() on entering SNK_DISCOVERY and
> SNK_READY and has no USB enumeration hook to raise a 100 mA limit 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>

> ---
>  drivers/usb/typec/tcpm/tcpci_maxim.h      |  8 ++++++++
>  drivers/usb/typec/tcpm/tcpci_maxim_core.c | 25 +++++++++++++++++++++++++
>  2 files changed, 33 insertions(+)
> 
> 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 a19f52515429..fb22a0dfb963 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>
> @@ -57,6 +58,29 @@ static struct max_tcpci_chip *tdata_to_max_tcpci(struct tcpci_data *tdata)
>  	return container_of(tdata, struct max_tcpci_chip, data);
>  }
>  
> +static int max_tcpci_get_current_limit(struct tcpci *tcpci,
> +				       struct tcpci_data *tdata)
> +{
> +	struct max_tcpci_chip *chip = tdata_to_max_tcpci(tdata);
> +	u8 status;
> +	int ret;
> +
> +	/* Relies on CHGDETEN being set; returns 0 until detection finishes. */
> +	ret = max_tcpci_read8(chip, TCPC_VENDOR_BC_STATUS1, &status);
> +	if (ret < 0)
> +		return 0;
> +
> +	switch (FIELD_GET(CHGTYP, status)) {
> +	case CHGTYP_SDP:
> +		return 500;
> +	case CHGTYP_CDP:
> +	case CHGTYP_DCP:
> +		return 1500;
> +	default:
> +		return 0;
> +	}
> +}
> +
>  static void max_tcpci_init_regs(struct max_tcpci_chip *chip)
>  {
>  	u16 alert_mask = 0;
> @@ -523,6 +547,7 @@ static int max_tcpci_probe(struct i2c_client *client)
>  	chip->data.check_contaminant = max_tcpci_check_contaminant;
>  	chip->data.cable_comm_capable = true;
>  	chip->data.attempt_vconn_swap_discovery = max_tcpci_attempt_vconn_swap_discovery;
> +	chip->data.get_current_limit = max_tcpci_get_current_limit;
>  
>  	max_tcpci_init_regs(chip);
>  	chip->tcpci = tcpci_register_port(chip->dev, &chip->data);
> 
> -- 
> 2.56.1.831.g720f3f5937-goog
> 

-- 
heikki

  reply	other threads:[~2026-11-30 13:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 14:04 [PATCH 0/2] usb: typec: tcpci: report BC1.2 current limit in tcpci_maxim André Draszik
2026-11-25 14:04 ` [PATCH 1/2] usb: typec: tcpci: add get_current_limit callback André Draszik
2026-11-30 13:02   ` Heikki Krogerus
2026-11-25 14:04 ` [PATCH 2/2] usb: typec: tcpm/tcpci_maxim: report BC1.2 current limit André Draszik
2026-11-30 13:03   ` Heikki Krogerus [this message]
2026-11-25 14:10 ` [PATCH 0/2] usb: typec: tcpci: report BC1.2 current limit in tcpci_maxim sashiko-bot

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=aw10J7J8mnkGMbOx@black.igk.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=amitsd@google.com \
    --cc=andre.draszik@linaro.org \
    --cc=badhri@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jyescas@google.com \
    --cc=kernel-team@android.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=peter.griffin@linaro.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