Skip to content

Commit 2e031f5

Browse files
Heikki Krogerusgregkh
authored andcommitted
usb: typec: ucsi: psy: Add support for the charge type property
Adding support for the charge type Linux power supply class property (POWER_SUPPLY_PROP_CHARGE_TYPE) to the UCSI driver. That will make the charge type visible in the charge_type power supply class sysfs attribute file. UCSI has the charge type specified in the Battery Charging Status field of the response to the GET_CONNECTOR_STATUS command. Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.com> Reviewed-by: Mario Limonciello <mario.limonciello@amd.com> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Link: https://lore.kernel.org/r/20240619140806.3502590-1-heikki.krogerus@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3560b37 commit 2e031f5

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

drivers/usb/typec/ucsi/psy.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ enum ucsi_psy_online_states {
2020
};
2121

2222
static enum power_supply_property ucsi_psy_props[] = {
23+
POWER_SUPPLY_PROP_CHARGE_TYPE,
2324
POWER_SUPPLY_PROP_USB_TYPE,
2425
POWER_SUPPLY_PROP_ONLINE,
2526
POWER_SUPPLY_PROP_VOLTAGE_MIN,
@@ -194,13 +195,44 @@ static int ucsi_psy_get_usb_type(struct ucsi_connector *con,
194195
return 0;
195196
}
196197

198+
static int ucsi_psy_get_charge_type(struct ucsi_connector *con, union power_supply_propval *val)
199+
{
200+
if (!(con->status.flags & UCSI_CONSTAT_CONNECTED)) {
201+
val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
202+
return 0;
203+
}
204+
205+
/* The Battery Charging Cabability Status field is only valid in sink role. */
206+
if ((con->status.flags & UCSI_CONSTAT_PWR_DIR) != TYPEC_SINK) {
207+
val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN;
208+
return 0;
209+
}
210+
211+
switch (UCSI_CONSTAT_BC_STATUS(con->status.pwr_status)) {
212+
case UCSI_CONSTAT_BC_NOMINAL_CHARGING:
213+
val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD;
214+
break;
215+
case UCSI_CONSTAT_BC_SLOW_CHARGING:
216+
case UCSI_CONSTAT_BC_TRICKLE_CHARGING:
217+
val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
218+
break;
219+
default:
220+
val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
221+
break;
222+
}
223+
224+
return 0;
225+
}
226+
197227
static int ucsi_psy_get_prop(struct power_supply *psy,
198228
enum power_supply_property psp,
199229
union power_supply_propval *val)
200230
{
201231
struct ucsi_connector *con = power_supply_get_drvdata(psy);
202232

203233
switch (psp) {
234+
case POWER_SUPPLY_PROP_CHARGE_TYPE:
235+
return ucsi_psy_get_charge_type(con, val);
204236
case POWER_SUPPLY_PROP_USB_TYPE:
205237
return ucsi_psy_get_usb_type(con, val);
206238
case POWER_SUPPLY_PROP_ONLINE:

drivers/usb/typec/ucsi/ucsi.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,9 @@ static void ucsi_handle_connector_change(struct work_struct *work)
12661266
if (con->status.change & UCSI_CONSTAT_CAM_CHANGE)
12671267
ucsi_partner_task(con, ucsi_check_altmodes, 1, HZ);
12681268

1269+
if (con->status.change & UCSI_CONSTAT_BC_CHANGE)
1270+
ucsi_port_psy_changed(con);
1271+
12691272
out_unlock:
12701273
mutex_unlock(&con->lock);
12711274
}

0 commit comments

Comments
 (0)