* [PATCH] usb: typec: ucsi: psy: Expose the charge-type property
@ 2024-06-17 10:55 Heikki Krogerus
2024-06-17 11:39 ` Greg Kroah-Hartman
2024-06-17 14:28 ` Sebastian Reichel
0 siblings, 2 replies; 4+ messages in thread
From: Heikki Krogerus @ 2024-06-17 10:55 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Mario Limonciello, Sebastian Reichel, linux-usb
UCSI has this information in the Battery Charging Capability
Status, so making it available for the user.
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
drivers/usb/typec/ucsi/psy.c | 27 +++++++++++++++++++++++++++
drivers/usb/typec/ucsi/ucsi.c | 3 +++
2 files changed, 30 insertions(+)
diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c
index b35c6e07911e..b3910f37e171 100644
--- a/drivers/usb/typec/ucsi/psy.c
+++ b/drivers/usb/typec/ucsi/psy.c
@@ -20,6 +20,7 @@ enum ucsi_psy_online_states {
};
static enum power_supply_property ucsi_psy_props[] = {
+ POWER_SUPPLY_PROP_CHARGE_TYPE,
POWER_SUPPLY_PROP_USB_TYPE,
POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_VOLTAGE_MIN,
@@ -194,6 +195,30 @@ static int ucsi_psy_get_usb_type(struct ucsi_connector *con,
return 0;
}
+static int ucsi_psy_get_charge_type(struct ucsi_connector *con, union power_supply_propval *val)
+{
+ if (!(con->status.flags & UCSI_CONSTAT_CONNECTED) ||
+ (con->status.flags & UCSI_CONSTAT_PWR_DIR) != TYPEC_SINK) {
+ val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
+ return 0;
+ }
+
+ switch (UCSI_CONSTAT_BC_STATUS(con->status.pwr_status)) {
+ case UCSI_CONSTAT_BC_NOMINAL_CHARGING:
+ val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD;
+ break;
+ case UCSI_CONSTAT_BC_SLOW_CHARGING:
+ case UCSI_CONSTAT_BC_TRICKLE_CHARGING:
+ val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
+ break;
+ default:
+ val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
+ break;
+ }
+
+ return 0;
+}
+
static int ucsi_psy_get_prop(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
@@ -201,6 +226,8 @@ static int ucsi_psy_get_prop(struct power_supply *psy,
struct ucsi_connector *con = power_supply_get_drvdata(psy);
switch (psp) {
+ case POWER_SUPPLY_PROP_CHARGE_TYPE:
+ return ucsi_psy_get_charge_type(con, val);
case POWER_SUPPLY_PROP_USB_TYPE:
return ucsi_psy_get_usb_type(con, val);
case POWER_SUPPLY_PROP_ONLINE:
diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 6bbaad4b89a5..51135e3502cf 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1257,6 +1257,9 @@ static void ucsi_handle_connector_change(struct work_struct *work)
if (con->status.change & UCSI_CONSTAT_CAM_CHANGE)
ucsi_partner_task(con, ucsi_check_altmodes, 1, HZ);
+ if (con->status.change & UCSI_CONSTAT_BC_CHANGE)
+ ucsi_port_psy_changed(con);
+
out_unlock:
mutex_unlock(&con->lock);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: typec: ucsi: psy: Expose the charge-type property
2024-06-17 10:55 [PATCH] usb: typec: ucsi: psy: Expose the charge-type property Heikki Krogerus
@ 2024-06-17 11:39 ` Greg Kroah-Hartman
2024-06-17 13:22 ` Heikki Krogerus
2024-06-17 14:28 ` Sebastian Reichel
1 sibling, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2024-06-17 11:39 UTC (permalink / raw)
To: Heikki Krogerus; +Cc: Mario Limonciello, Sebastian Reichel, linux-usb
On Mon, Jun 17, 2024 at 01:55:54PM +0300, Heikki Krogerus wrote:
> UCSI has this information in the Battery Charging Capability
> Status, so making it available for the user.
Make it availble how? To what user? Through what api?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: typec: ucsi: psy: Expose the charge-type property
2024-06-17 11:39 ` Greg Kroah-Hartman
@ 2024-06-17 13:22 ` Heikki Krogerus
0 siblings, 0 replies; 4+ messages in thread
From: Heikki Krogerus @ 2024-06-17 13:22 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Mario Limonciello, Sebastian Reichel, linux-usb
On Mon, Jun 17, 2024 at 01:39:17PM +0200, Greg Kroah-Hartman wrote:
> On Mon, Jun 17, 2024 at 01:55:54PM +0300, Heikki Krogerus wrote:
> > UCSI has this information in the Battery Charging Capability
> > Status, so making it available for the user.
>
> Make it availble how? To what user? Through what api?
This is for the power supply interface. The charge type sysfs
attribute file [1] is hidden with the UCSI power supplies. This would
"unhide" it.
I'll rewrite the commit message.
[1] https://docs.kernel.org/admin-guide/abi-testing.html#abi-sys-class-power-supply-supply-name-charge-type
thanks,
--
heikki
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] usb: typec: ucsi: psy: Expose the charge-type property
2024-06-17 10:55 [PATCH] usb: typec: ucsi: psy: Expose the charge-type property Heikki Krogerus
2024-06-17 11:39 ` Greg Kroah-Hartman
@ 2024-06-17 14:28 ` Sebastian Reichel
1 sibling, 0 replies; 4+ messages in thread
From: Sebastian Reichel @ 2024-06-17 14:28 UTC (permalink / raw)
To: Heikki Krogerus; +Cc: Greg Kroah-Hartman, Mario Limonciello, linux-usb
[-- Attachment #1: Type: text/plain, Size: 2922 bytes --]
Hi,
On Mon, Jun 17, 2024 at 01:55:54PM GMT, Heikki Krogerus wrote:
> UCSI has this information in the Battery Charging Capability
> Status, so making it available for the user.
>
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com>
-- Sebastian
> drivers/usb/typec/ucsi/psy.c | 27 +++++++++++++++++++++++++++
> drivers/usb/typec/ucsi/ucsi.c | 3 +++
> 2 files changed, 30 insertions(+)
>
> diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c
> index b35c6e07911e..b3910f37e171 100644
> --- a/drivers/usb/typec/ucsi/psy.c
> +++ b/drivers/usb/typec/ucsi/psy.c
> @@ -20,6 +20,7 @@ enum ucsi_psy_online_states {
> };
>
> static enum power_supply_property ucsi_psy_props[] = {
> + POWER_SUPPLY_PROP_CHARGE_TYPE,
> POWER_SUPPLY_PROP_USB_TYPE,
> POWER_SUPPLY_PROP_ONLINE,
> POWER_SUPPLY_PROP_VOLTAGE_MIN,
> @@ -194,6 +195,30 @@ static int ucsi_psy_get_usb_type(struct ucsi_connector *con,
> return 0;
> }
>
> +static int ucsi_psy_get_charge_type(struct ucsi_connector *con, union power_supply_propval *val)
> +{
> + if (!(con->status.flags & UCSI_CONSTAT_CONNECTED) ||
> + (con->status.flags & UCSI_CONSTAT_PWR_DIR) != TYPEC_SINK) {
> + val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
> + return 0;
> + }
> +
> + switch (UCSI_CONSTAT_BC_STATUS(con->status.pwr_status)) {
> + case UCSI_CONSTAT_BC_NOMINAL_CHARGING:
> + val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD;
> + break;
> + case UCSI_CONSTAT_BC_SLOW_CHARGING:
> + case UCSI_CONSTAT_BC_TRICKLE_CHARGING:
> + val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
> + break;
> + default:
> + val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
> + break;
> + }
> +
> + return 0;
> +}
> +
> static int ucsi_psy_get_prop(struct power_supply *psy,
> enum power_supply_property psp,
> union power_supply_propval *val)
> @@ -201,6 +226,8 @@ static int ucsi_psy_get_prop(struct power_supply *psy,
> struct ucsi_connector *con = power_supply_get_drvdata(psy);
>
> switch (psp) {
> + case POWER_SUPPLY_PROP_CHARGE_TYPE:
> + return ucsi_psy_get_charge_type(con, val);
> case POWER_SUPPLY_PROP_USB_TYPE:
> return ucsi_psy_get_usb_type(con, val);
> case POWER_SUPPLY_PROP_ONLINE:
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 6bbaad4b89a5..51135e3502cf 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1257,6 +1257,9 @@ static void ucsi_handle_connector_change(struct work_struct *work)
> if (con->status.change & UCSI_CONSTAT_CAM_CHANGE)
> ucsi_partner_task(con, ucsi_check_altmodes, 1, HZ);
>
> + if (con->status.change & UCSI_CONSTAT_BC_CHANGE)
> + ucsi_port_psy_changed(con);
> +
> out_unlock:
> mutex_unlock(&con->lock);
> }
> --
> 2.43.0
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-06-17 14:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-17 10:55 [PATCH] usb: typec: ucsi: psy: Expose the charge-type property Heikki Krogerus
2024-06-17 11:39 ` Greg Kroah-Hartman
2024-06-17 13:22 ` Heikki Krogerus
2024-06-17 14:28 ` Sebastian Reichel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox