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.

Dependency Surface

Detected Declarations

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

Implementation Notes