drivers/usb/typec/mux/fsa4480.c

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

File Facts

System
Linux kernel
Corpus path
drivers/usb/typec/mux/fsa4480.c
Extension
.c
Size
9124 bytes
Lines
363
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 fsa4480 {
	struct i2c_client *client;

	/* used to serialize concurrent change requests */
	struct mutex lock;

	struct typec_switch_dev *sw;
	struct typec_mux_dev *mux;

	struct regmap *regmap;

	enum typec_orientation orientation;
	unsigned long mode;
	unsigned int svid;

	u8 cur_enable;
	bool swap_sbu_lanes;
};

static const struct regmap_config fsa4480_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
	.max_register = FSA4480_MAX_REGISTER,
	/* Accesses only done under fsa4480->lock */
	.disable_locking = true,
};

static int fsa4480_set(struct fsa4480 *fsa)
{
	bool reverse = (fsa->orientation == TYPEC_ORIENTATION_REVERSE);
	u8 enable = FSA4480_ENABLE_DEVICE;
	u8 sel = 0;

	if (fsa->swap_sbu_lanes)
		reverse = !reverse;

	/* USB Mode */
	if (fsa->mode < TYPEC_STATE_MODAL ||
	    (!fsa->svid && (fsa->mode == TYPEC_MODE_USB2 ||
			    fsa->mode == TYPEC_MODE_USB3))) {
		enable |= FSA4480_ENABLE_USB;
		sel = FSA4480_SEL_USB;
	} else if (fsa->svid) {
		switch (fsa->mode) {
		/* DP Only */
		case TYPEC_DP_STATE_C:
		case TYPEC_DP_STATE_E:
			enable |= FSA4480_ENABLE_SBU;
			if (reverse)
				sel = FSA4480_SEL_SBU_REVERSE;
			break;

		/* DP + USB */
		case TYPEC_DP_STATE_D:
		case TYPEC_DP_STATE_F:
			enable |= FSA4480_ENABLE_USB | FSA4480_ENABLE_SBU;
			sel = FSA4480_SEL_USB;
			if (reverse)
				sel |= FSA4480_SEL_SBU_REVERSE;
			break;

		default:
			return -EOPNOTSUPP;
		}
	} else if (fsa->mode == TYPEC_MODE_AUDIO) {
		/* Audio Accessory Mode, setup to auto Jack Detection */
		enable |= FSA4480_ENABLE_USB | FSA4480_ENABLE_AGND;
	} else
		return -EOPNOTSUPP;

	if (fsa->cur_enable & FSA4480_ENABLE_SBU) {
		/* Disable SBU output while re-configuring the switch */
		regmap_write(fsa->regmap, FSA4480_SWITCH_ENABLE,
			     fsa->cur_enable & ~FSA4480_ENABLE_SBU);

		/* 35us to allow the SBU switch to turn off */
		usleep_range(35, 1000);
	}

	regmap_write(fsa->regmap, FSA4480_SWITCH_SELECT, sel);
	regmap_write(fsa->regmap, FSA4480_SWITCH_ENABLE, enable);

	/* Start AUDIO JACK DETECTION to setup MIC, AGND & Sense muxes */
	if (enable & FSA4480_ENABLE_AGND)
		regmap_write(fsa->regmap, FSA4480_FUNCTION_ENABLE,
			     FSA4480_ENABLE_AUTO_JACK_DETECT);

	if (enable & FSA4480_ENABLE_SBU) {
		/* 15us to allow the SBU switch to turn on again */
		usleep_range(15, 1000);

Annotation

Implementation Notes