From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Jameson Thies <jthies@google.com>
Cc: 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,
linux-pm@vger.kernel.org
Subject: Re: [PATCH 1/6] usb: typec: ucsi: psy: Add power supply status
Date: Wed, 8 Oct 2025 15:53:44 +0300 [thread overview]
Message-ID: <aOZe2CbQuT2J8Itd@kuha.fi.intel.com> (raw)
In-Reply-To: <20251007000007.3724229-2-jthies@google.com>
On Tue, Oct 07, 2025 at 12:00:02AM +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>
> ---
> 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.618.g983fd99d29-goog
--
heikki
next prev parent reply other threads:[~2025-10-08 12:53 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-07 0:00 [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes Jameson Thies
2025-10-07 0:00 ` [PATCH 1/6] usb: typec: ucsi: psy: Add power supply status Jameson Thies
2025-10-08 12:53 ` Heikki Krogerus [this message]
2025-10-07 0:00 ` [PATCH 2/6] usb: typec: ucsi: psy: Add support for DRP USB type Jameson Thies
2025-10-07 23:50 ` Benson Leung
2025-10-08 13:02 ` Heikki Krogerus
2025-10-13 20:44 ` Jameson Thies
2025-10-07 0:00 ` [PATCH 3/6] usb: typec: ucsi: Report power supply changes on power opmode changes Jameson Thies
2025-10-07 23:51 ` Benson Leung
2025-10-08 13:02 ` Heikki Krogerus
2025-10-07 0:00 ` [PATCH 4/6] usb: typec: ucsi: Report power supply change on sink path change Jameson Thies
2025-10-07 23:52 ` Benson Leung
2025-10-08 13:06 ` Heikki Krogerus
2025-10-13 20:45 ` Jameson Thies
2025-10-07 0:00 ` [PATCH 5/6] usb: typec: ucsi: psy: Set max current to zero when disconnected Jameson Thies
2025-10-07 23:55 ` Benson Leung
2025-10-08 13:08 ` Heikki Krogerus
2025-10-07 0:00 ` [PATCH 6/6] usb: typec: ucsi: pr_swap should check connector_status Jameson Thies
2025-10-07 23:56 ` Benson Leung
2025-10-08 13:10 ` Heikki Krogerus
2025-10-13 20:56 ` Jameson Thies
2025-10-13 7:33 ` [PATCH 0/6] UCSI Power Supply Updates and Bug Fixes Greg KH
2025-10-13 20:59 ` Jameson Thies
2025-10-14 5:19 ` Greg KH
2025-10-13 21:02 ` Kenneth Crudup
2025-10-13 22:53 ` Jameson Thies
2025-10-13 23:26 ` 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=aOZe2CbQuT2J8Itd@kuha.fi.intel.com \
--to=heikki.krogerus@linux.intel.com \
--cc=abhishekpandit@chromium.org \
--cc=akuchynski@chromium.org \
--cc=bleung@chromium.org \
--cc=dmitry.baryshkov@oss.qualcomm.com \
--cc=gregkh@linuxfoundation.org \
--cc=jthies@google.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).