From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Badhri Jagan Sridharan <badhri@google.com>
Cc: gregkh@linuxfoundation.org, amitsd@google.com,
kyletso@google.com, rdbabiera@google.com,
linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 1/2] tcpm: Parse and log AVS APDO
Date: Mon, 20 Oct 2025 12:51:17 +0300 [thread overview]
Message-ID: <aPYGFdrnJ0OHaEjp@kuha.fi.intel.com> (raw)
In-Reply-To: <20251015043017.3382908-1-badhri@google.com>
On Wed, Oct 15, 2025 at 04:30:13AM +0000, Badhri Jagan Sridharan wrote:
> The USB PD specification introduced new Adjustable Voltage Supply (AVS)
> types for both Standard Power Range (SPR) and Extended Power Range (EPR)
> sources.
>
> Add definitions to correctly parse and handle the new AVS APDO. Use
> bitfield macros to add inline helper functions to extract voltage,
> current, power, and peak current fields to parse and log the details
> of the new EPR AVS and SPR AVS APDO.
>
> Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
> Reviewed-by: Amit Sunil Dhamne <amitsd@google.com>
> Reviewed-by: Kyle Tso <kyletso@google.com>
> Reviewed-by: RD Babiera <rdbabiera@google.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
> Changes since v1:
> * Fixed incorrrect squash.
> ---
> drivers/usb/typec/tcpm/tcpm.c | 15 +++++++-
> include/linux/usb/pd.h | 69 ++++++++++++++++++++++++++++++++++-
> 2 files changed, 82 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index b2a568a5bc9b..c65aa8104950 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -823,10 +823,23 @@ static void tcpm_log_source_caps(struct tcpm_port *port)
> case PDO_TYPE_APDO:
> if (pdo_apdo_type(pdo) == APDO_TYPE_PPS)
> scnprintf(msg, sizeof(msg),
> - "%u-%u mV, %u mA",
> + "PPS %u-%u mV, %u mA",
> pdo_pps_apdo_min_voltage(pdo),
> pdo_pps_apdo_max_voltage(pdo),
> pdo_pps_apdo_max_current(pdo));
> + else if (pdo_apdo_type(pdo) == APDO_TYPE_EPR_AVS)
> + scnprintf(msg, sizeof(msg),
> + "EPR AVS %u-%u mV %u W peak_current: %u",
> + pdo_epr_avs_apdo_min_voltage_mv(pdo),
> + pdo_epr_avs_apdo_max_voltage_mv(pdo),
> + pdo_epr_avs_apdo_pdp_w(pdo),
> + pdo_epr_avs_apdo_src_peak_current(pdo));
> + else if (pdo_apdo_type(pdo) == APDO_TYPE_SPR_AVS)
> + scnprintf(msg, sizeof(msg),
> + "SPR AVS 9-15 V: %u mA 15-20 V: %u mA peak_current: %u",
> + pdo_spr_avs_apdo_9v_to_15v_max_current_ma(pdo),
> + pdo_spr_avs_apdo_15v_to_20v_max_current_ma(pdo),
> + pdo_spr_avs_apdo_src_peak_current(pdo));
> else
> strcpy(msg, "undefined APDO");
> break;
> diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h
> index 3068c3084eb6..6ccd1b2af993 100644
> --- a/include/linux/usb/pd.h
> +++ b/include/linux/usb/pd.h
> @@ -6,6 +6,7 @@
> #ifndef __LINUX_USB_PD_H
> #define __LINUX_USB_PD_H
>
> +#include <linux/bitfield.h>
> #include <linux/kernel.h>
> #include <linux/types.h>
> #include <linux/usb/typec.h>
> @@ -271,9 +272,11 @@ enum pd_pdo_type {
>
> enum pd_apdo_type {
> APDO_TYPE_PPS = 0,
> + APDO_TYPE_EPR_AVS = 1,
> + APDO_TYPE_SPR_AVS = 2,
> };
>
> -#define PDO_APDO_TYPE_SHIFT 28 /* Only valid value currently is 0x0 - PPS */
> +#define PDO_APDO_TYPE_SHIFT 28
> #define PDO_APDO_TYPE_MASK 0x3
>
> #define PDO_APDO_TYPE(t) ((t) << PDO_APDO_TYPE_SHIFT)
> @@ -297,6 +300,35 @@ enum pd_apdo_type {
> PDO_PPS_APDO_MIN_VOLT(min_mv) | PDO_PPS_APDO_MAX_VOLT(max_mv) | \
> PDO_PPS_APDO_MAX_CURR(max_ma))
>
> +/*
> + * Applicable only to EPR AVS APDO source cap as per
> + * Table 6.15 EPR Adjustable Voltage Supply APDO – Source
> + */
> +#define PDO_EPR_AVS_APDO_PEAK_CURRENT GENMASK(27, 26)
> +
> +/*
> + * Applicable to both EPR AVS APDO source and sink cap as per
> + * Table 6.15 EPR Adjustable Voltage Supply APDO – Source
> + * Table 6.22 EPR Adjustable Voltage Supply APDO – Sink
> + */
> +#define PDO_EPR_AVS_APDO_MAX_VOLT GENMASK(25, 17) /* 100mV unit */
> +#define PDO_EPR_AVS_APDO_MIN_VOLT GENMASK(15, 8) /* 100mV unit */
> +#define PDO_EPR_AVS_APDO_PDP GENMASK(7, 0) /* 1W unit */
> +
> +/*
> + * Applicable only SPR AVS APDO source cap as per
> + * Table 6.14 SPR Adjustable Voltage Supply APDO – Source
> + */
> +#define PDO_SPR_AVS_APDO_PEAK_CURRENT GENMASK(27, 26)
> +
> +/*
> + * Applicable to both SPR AVS APDO source and sink cap as per
> + * Table 6.14 SPR Adjustable Voltage Supply APDO – Source
> + * Table 6.21 SPR Adjustable Voltage Supply APDO – Sink
> + */
> +#define PDO_SPR_AVS_APDO_9V_TO_15V_MAX_CURR GENMASK(19, 10) /* 10mA unit */
> +#define PDO_SPR_AVS_APDO_15V_TO_20V_MAX_CURR GENMASK(9, 0) /* 10mA unit */
> +
> static inline enum pd_pdo_type pdo_type(u32 pdo)
> {
> return (pdo >> PDO_TYPE_SHIFT) & PDO_TYPE_MASK;
> @@ -350,6 +382,41 @@ static inline unsigned int pdo_pps_apdo_max_current(u32 pdo)
> PDO_PPS_APDO_CURR_MASK) * 50;
> }
>
> +static inline unsigned int pdo_epr_avs_apdo_src_peak_current(u32 pdo)
> +{
> + return FIELD_GET(PDO_EPR_AVS_APDO_PEAK_CURRENT, pdo);
> +}
> +
> +static inline unsigned int pdo_epr_avs_apdo_min_voltage_mv(u32 pdo)
> +{
> + return FIELD_GET(PDO_EPR_AVS_APDO_MIN_VOLT, pdo) * 100;
> +}
> +
> +static inline unsigned int pdo_epr_avs_apdo_max_voltage_mv(u32 pdo)
> +{
> + return FIELD_GET(PDO_EPR_AVS_APDO_MIN_VOLT, pdo) * 100;
> +}
> +
> +static inline unsigned int pdo_epr_avs_apdo_pdp_w(u32 pdo)
> +{
> + return FIELD_GET(PDO_EPR_AVS_APDO_PDP, pdo);
> +}
> +
> +static inline unsigned int pdo_spr_avs_apdo_src_peak_current(u32 pdo)
> +{
> + return FIELD_GET(PDO_SPR_AVS_APDO_PEAK_CURRENT, pdo);
> +}
> +
> +static inline unsigned int pdo_spr_avs_apdo_9v_to_15v_max_current_ma(u32 pdo)
> +{
> + return FIELD_GET(PDO_SPR_AVS_APDO_9V_TO_15V_MAX_CURR, pdo) * 10;
> +}
> +
> +static inline unsigned int pdo_spr_avs_apdo_15v_to_20v_max_current_ma(u32 pdo)
> +{
> + return FIELD_GET(PDO_SPR_AVS_APDO_15V_TO_20V_MAX_CURR, pdo) * 10;
> +}
> +
> /* RDO: Request Data Object */
> #define RDO_OBJ_POS_SHIFT 28
> #define RDO_OBJ_POS_MASK 0x7
>
> base-commit: 877c80dfbf788e57a3338627899033b7007037ee
> --
> 2.51.0.858.gf9c4a03a3a-goog
--
heikki
prev parent reply other threads:[~2025-10-20 9:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 4:30 Badhri Jagan Sridharan
2025-10-15 4:30 ` [PATCH v2 2/2] usb: typec: pd: Register SPR AVS caps with usb_power_delivery class Badhri Jagan Sridharan
2025-10-20 9:52 ` Heikki Krogerus
2025-10-20 9:51 ` Heikki Krogerus [this message]
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=aPYGFdrnJ0OHaEjp@kuha.fi.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=amitsd@google.com \
--cc=badhri@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=kyletso@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=rdbabiera@google.com \
/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
all inboxes | Powered by JetHome®