drivers/usb/typec/wusb3801.c

Source file repositories/reference/linux-study-clean/drivers/usb/typec/wusb3801.c

File Facts

System
Linux kernel
Corpus path
drivers/usb/typec/wusb3801.c
Extension
.c
Size
11770 bytes
Lines
436
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

struct wusb3801 {
	struct typec_capability	cap;
	struct device		*dev;
	struct typec_partner	*partner;
	struct typec_port	*port;
	struct regmap		*regmap;
	struct regulator	*vbus_supply;
	unsigned int		partner_type;
	enum typec_port_type	port_type;
	enum typec_pwr_opmode	pwr_opmode;
	bool			vbus_on;
};

static enum typec_role wusb3801_get_default_role(struct wusb3801 *wusb3801)
{
	switch (wusb3801->port_type) {
	case TYPEC_PORT_SRC:
		return TYPEC_SOURCE;
	case TYPEC_PORT_SNK:
		return TYPEC_SINK;
	case TYPEC_PORT_DRP:
	default:
		if (wusb3801->cap.prefer_role == TYPEC_SOURCE)
			return TYPEC_SOURCE;
		return TYPEC_SINK;
	}
}

static int wusb3801_map_port_type(enum typec_port_type type)
{
	switch (type) {
	case TYPEC_PORT_SRC:
		return WUSB3801_CTRL0_ROLE_SRC;
	case TYPEC_PORT_SNK:
		return WUSB3801_CTRL0_ROLE_SNK;
	case TYPEC_PORT_DRP:
	default:
		return WUSB3801_CTRL0_ROLE_DRP;
	}
}

static int wusb3801_map_pwr_opmode(enum typec_pwr_opmode mode)
{
	switch (mode) {
	case TYPEC_PWR_MODE_USB:
	default:
		return WUSB3801_CTRL0_CURRENT_DEFAULT;
	case TYPEC_PWR_MODE_1_5A:
		return WUSB3801_CTRL0_CURRENT_1_5A;
	case TYPEC_PWR_MODE_3_0A:
		return WUSB3801_CTRL0_CURRENT_3_0A;
	}
}

static unsigned int wusb3801_map_try_role(int role)
{
	switch (role) {
	case TYPEC_NO_PREFERRED_ROLE:
	default:
		return WUSB3801_CTRL0_TRY_NONE;
	case TYPEC_SINK:
		return WUSB3801_CTRL0_TRY_SNK;
	case TYPEC_SOURCE:
		return WUSB3801_CTRL0_TRY_SRC;
	}
}

static enum typec_orientation wusb3801_unmap_orientation(unsigned int status)
{
	switch (status & WUSB3801_STAT_ORIENTATION) {
	case WUSB3801_STAT_ORIENTATION_NONE:
	case WUSB3801_STAT_ORIENTATION_BOTH:
	default:
		return TYPEC_ORIENTATION_NONE;
	case WUSB3801_STAT_ORIENTATION_CC1:
		return TYPEC_ORIENTATION_NORMAL;
	case WUSB3801_STAT_ORIENTATION_CC2:
		return TYPEC_ORIENTATION_REVERSE;
	}
}

static enum typec_pwr_opmode wusb3801_unmap_pwr_opmode(unsigned int status)
{
	switch (status & WUSB3801_STAT_CURRENT) {
	case WUSB3801_STAT_CURRENT_STANDBY:
	case WUSB3801_STAT_CURRENT_DEFAULT:
	default:
		return TYPEC_PWR_MODE_USB;
	case WUSB3801_STAT_CURRENT_1_5A:
		return TYPEC_PWR_MODE_1_5A;

Annotation

Implementation Notes