drivers/usb/typec/ucsi/psy.c
Source file repositories/reference/linux-study-clean/drivers/usb/typec/ucsi/psy.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/typec/ucsi/psy.c- Extension
.c- Size
- 9141 bytes
- Lines
- 356
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/property.hlinux/usb/pd.hucsi.h
Detected Declarations
enum ucsi_psy_online_statesfunction ucsi_psy_get_scopefunction ucsi_psy_get_statusfunction ucsi_psy_get_onlinefunction ucsi_psy_get_voltage_minfunction ucsi_psy_get_voltage_maxfunction ucsi_psy_get_voltage_nowfunction ucsi_psy_get_current_maxfunction ucsi_psy_get_current_nowfunction ucsi_psy_get_usb_typefunction ucsi_psy_get_charge_typefunction ucsi_psy_get_propfunction ucsi_register_port_psyfunction ucsi_unregister_port_psyfunction ucsi_port_psy_changed
Annotated Snippet
if (index > 0) {
pdo = con->src_pdos[index - 1];
val->intval = pdo_fixed_voltage(pdo) * 1000;
} else {
val->intval = 0;
}
break;
case UCSI_CONSTAT_PWR_OPMODE_TYPEC3_0:
case UCSI_CONSTAT_PWR_OPMODE_TYPEC1_5:
case UCSI_CONSTAT_PWR_OPMODE_BC:
case UCSI_CONSTAT_PWR_OPMODE_DEFAULT:
val->intval = UCSI_TYPEC_VSAFE5V * 1000;
break;
default:
val->intval = 0;
break;
}
return 0;
}
static int ucsi_psy_get_current_max(struct ucsi_connector *con,
union power_supply_propval *val)
{
u32 pdo;
int max_current = 0;
if (!UCSI_CONSTAT(con, CONNECTED)) {
val->intval = 0;
return 0;
}
switch (UCSI_CONSTAT(con, PWR_OPMODE)) {
case UCSI_CONSTAT_PWR_OPMODE_PD:
for (int i = 0; i < con->num_pdos; i++) {
int pdo_current = 0;
pdo = con->src_pdos[i];
if (pdo_type(pdo) == PDO_TYPE_FIXED)
pdo_current = pdo_max_current(pdo) * 1000;
max_current = (pdo_current > max_current) ? pdo_current
: max_current;
}
val->intval = max_current;
break;
case UCSI_CONSTAT_PWR_OPMODE_TYPEC1_5:
val->intval = UCSI_TYPEC_1_5_CURRENT * 1000;
break;
case UCSI_CONSTAT_PWR_OPMODE_TYPEC3_0:
val->intval = UCSI_TYPEC_3_0_CURRENT * 1000;
break;
case UCSI_CONSTAT_PWR_OPMODE_BC:
case UCSI_CONSTAT_PWR_OPMODE_DEFAULT:
/* UCSI can't tell b/w DCP/CDP or USB2/3x1/3x2 SDP chargers */
default:
val->intval = UCSI_TYPEC_DEFAULT_CURRENT * 1000;
break;
}
return 0;
}
static int ucsi_psy_get_current_now(struct ucsi_connector *con,
union power_supply_propval *val)
{
if (!UCSI_CONSTAT(con, CONNECTED)) {
val->intval = 0;
return 0;
}
switch (UCSI_CONSTAT(con, PWR_OPMODE)) {
case UCSI_CONSTAT_PWR_OPMODE_PD:
val->intval = rdo_op_current(con->rdo) * 1000;
break;
case UCSI_CONSTAT_PWR_OPMODE_TYPEC1_5:
val->intval = UCSI_TYPEC_1_5_CURRENT * 1000;
break;
case UCSI_CONSTAT_PWR_OPMODE_TYPEC3_0:
val->intval = UCSI_TYPEC_3_0_CURRENT * 1000;
break;
case UCSI_CONSTAT_PWR_OPMODE_BC:
case UCSI_CONSTAT_PWR_OPMODE_DEFAULT:
/* UCSI can't tell b/w DCP/CDP or USB2/3x1/3x2 SDP chargers */
default:
val->intval = UCSI_TYPEC_DEFAULT_CURRENT * 1000;
break;
}
return 0;
}
static int ucsi_psy_get_usb_type(struct ucsi_connector *con,
union power_supply_propval *val)
Annotation
- Immediate include surface: `linux/property.h`, `linux/usb/pd.h`, `ucsi.h`.
- Detected declarations: `enum ucsi_psy_online_states`, `function ucsi_psy_get_scope`, `function ucsi_psy_get_status`, `function ucsi_psy_get_online`, `function ucsi_psy_get_voltage_min`, `function ucsi_psy_get_voltage_max`, `function ucsi_psy_get_voltage_now`, `function ucsi_psy_get_current_max`, `function ucsi_psy_get_current_now`, `function ucsi_psy_get_usb_type`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.