From: Benson Leung <bleung@google.com>
To: Jameson Thies <jthies@google.com>
Cc: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org, dmitry.baryshkov@oss.qualcomm.com,
bleung@chromium.org, gregkh@linuxfoundation.org,
akuchynski@chromium.org, abhishekpandit@chromium.org,
sebastian.reichel@collabora.com, kenny@panix.com,
linux-pm@vger.kernel.org
Subject: Re: [PATCH v2 1/3] usb: typec: ucsi: psy: Add power supply status
Date: Fri, 17 Oct 2025 00:09:06 +0000 [thread overview]
Message-ID: <aPGJImOPx4yCWQnv@google.com> (raw)
In-Reply-To: <20251016235909.2092917-2-jthies@google.com>
[-- Attachment #1: Type: text/plain, Size: 3276 bytes --]
On Thu, Oct 16, 2025 at 11:59:07PM +0000, Jameson Thies wrote:
> Add support for power supply status. If a port is acting as a sink
> with the sink path enabled, report it is charging. If a port is
> source, report it is discharging. If there is no connection or the
> port hasn't enabled the sink path, report not charging.
>
> Signed-off-by: Jameson Thies <jthies@google.com>
> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Benson Leung <bleung@chromium.org>
> ---
> drivers/usb/typec/ucsi/psy.c | 26 ++++++++++++++++++++++++++
> drivers/usb/typec/ucsi/ucsi.h | 3 +++
> 2 files changed, 29 insertions(+)
>
> diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c
> index 62a9d68bb66d..2b0225821502 100644
> --- a/drivers/usb/typec/ucsi/psy.c
> +++ b/drivers/usb/typec/ucsi/psy.c
> @@ -29,6 +29,7 @@ static enum power_supply_property ucsi_psy_props[] = {
> POWER_SUPPLY_PROP_CURRENT_MAX,
> POWER_SUPPLY_PROP_CURRENT_NOW,
> POWER_SUPPLY_PROP_SCOPE,
> + POWER_SUPPLY_PROP_STATUS,
> };
>
> static int ucsi_psy_get_scope(struct ucsi_connector *con,
> @@ -51,6 +52,29 @@ static int ucsi_psy_get_scope(struct ucsi_connector *con,
> return 0;
> }
>
> +static int ucsi_psy_get_status(struct ucsi_connector *con,
> + union power_supply_propval *val)
> +{
> + bool is_sink = UCSI_CONSTAT(con, PWR_DIR) == TYPEC_SINK;
> + bool sink_path_enabled = true;
> +
> + val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
> +
> + if (con->ucsi->version >= UCSI_VERSION_2_0)
> + sink_path_enabled =
> + UCSI_CONSTAT(con, SINK_PATH_STATUS_V2_0) ==
> + UCSI_CONSTAT_SINK_PATH_ENABLED;
> +
> + if (UCSI_CONSTAT(con, CONNECTED)) {
> + if (is_sink && sink_path_enabled)
> + val->intval = POWER_SUPPLY_STATUS_CHARGING;
> + else if (!is_sink)
> + val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
> + }
> +
> + return 0;
> +}
> +
> static int ucsi_psy_get_online(struct ucsi_connector *con,
> union power_supply_propval *val)
> {
> @@ -245,6 +269,8 @@ static int ucsi_psy_get_prop(struct power_supply *psy,
> return ucsi_psy_get_current_now(con, val);
> case POWER_SUPPLY_PROP_SCOPE:
> return ucsi_psy_get_scope(con, val);
> + case POWER_SUPPLY_PROP_STATUS:
> + return ucsi_psy_get_status(con, val);
> default:
> return -EINVAL;
> }
> diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
> index e301d9012936..cce93af7461b 100644
> --- a/drivers/usb/typec/ucsi/ucsi.h
> +++ b/drivers/usb/typec/ucsi/ucsi.h
> @@ -360,6 +360,9 @@ struct ucsi_cable_property {
> #define UCSI_CONSTAT_BC_SLOW_CHARGING 2
> #define UCSI_CONSTAT_BC_TRICKLE_CHARGING 3
> #define UCSI_CONSTAT_PD_VERSION_V1_2 UCSI_DECLARE_BITFIELD_V1_2(70, 16)
> +#define UCSI_CONSTAT_SINK_PATH_STATUS_V2_0 UCSI_DECLARE_BITFIELD_V2_0(87, 1)
> +#define UCSI_CONSTAT_SINK_PATH_DISABLED 0
> +#define UCSI_CONSTAT_SINK_PATH_ENABLED 1
> #define UCSI_CONSTAT_PWR_READING_READY_V2_1 UCSI_DECLARE_BITFIELD_V2_1(89, 1)
> #define UCSI_CONSTAT_CURRENT_SCALE_V2_1 UCSI_DECLARE_BITFIELD_V2_1(90, 3)
> #define UCSI_CONSTAT_PEAK_CURRENT_V2_1 UCSI_DECLARE_BITFIELD_V2_1(93, 16)
> --
> 2.51.0.858.gf9c4a03a3a-goog
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2025-10-17 0:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-16 23:59 [PATCH v2 0/3] UCSI Power Supply Updates Jameson Thies
2025-10-16 23:59 ` [PATCH v2 1/3] usb: typec: ucsi: psy: Add power supply status Jameson Thies
2025-10-17 0:09 ` Benson Leung [this message]
2025-10-16 23:59 ` [PATCH v2 2/3] usb: typec: ucsi: Report power supply changes on power opmode changes Jameson Thies
2025-10-16 23:59 ` [PATCH v2 3/3] usb: typec: ucsi: Report power supply change on sink path change Jameson Thies
2025-10-17 0:11 ` Benson Leung
2025-10-17 0:16 ` [PATCH v2 0/3] UCSI Power Supply Updates Kenneth Crudup
2025-10-17 0:25 ` Kenneth Crudup
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=aPGJImOPx4yCWQnv@google.com \
--to=bleung@google.com \
--cc=abhishekpandit@chromium.org \
--cc=akuchynski@chromium.org \
--cc=bleung@chromium.org \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=jthies@google.com \
--cc=kenny@panix.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sebastian.reichel@collabora.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;
as well as URLs for NNTP newsgroup(s).