[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aPGJImOPx4yCWQnv@google.com>
Date: Fri, 17 Oct 2025 00:09:06 +0000
From: Benson Leung <bleung@...gle.com>
To: Jameson Thies <jthies@...gle.com>
Cc: heikki.krogerus@...ux.intel.com, linux-usb@...r.kernel.org,
linux-kernel@...r.kernel.org, dmitry.baryshkov@....qualcomm.com,
bleung@...omium.org, gregkh@...uxfoundation.org,
akuchynski@...omium.org, abhishekpandit@...omium.org,
sebastian.reichel@...labora.com, kenny@...ix.com,
linux-pm@...r.kernel.org
Subject: Re: [PATCH v2 1/3] usb: typec: ucsi: psy: Add power supply status
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@...gle.com>
> Reviewed-by: Heikki Krogerus <heikki.krogerus@...ux.intel.com>
Reviewed-by: Benson Leung <bleung@...omium.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
>
Download attachment "signature.asc" of type "application/pgp-signature" (229 bytes)
Powered by blists - more mailing lists