drivers/usb/typec/tcpm/tcpci_rt1711h.c

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

File Facts

System
Linux kernel
Corpus path
drivers/usb/typec/tcpm/tcpci_rt1711h.c
Extension
.c
Size
10448 bytes
Lines
405
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 rt1711h_chip_info {
	u32 rxdz_sel;
	bool enable_pd30_extended_message;
};

struct rt1711h_chip {
	struct tcpci_data data;
	struct tcpci *tcpci;
	struct device *dev;
	struct regulator *vbus;
	const struct rt1711h_chip_info *info;
	bool src_en;
};

static int rt1711h_read16(struct rt1711h_chip *chip, unsigned int reg, u16 *val)
{
	return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u16));
}

static int rt1711h_write16(struct rt1711h_chip *chip, unsigned int reg, u16 val)
{
	return regmap_raw_write(chip->data.regmap, reg, &val, sizeof(u16));
}

static int rt1711h_read8(struct rt1711h_chip *chip, unsigned int reg, u8 *val)
{
	return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u8));
}

static int rt1711h_write8(struct rt1711h_chip *chip, unsigned int reg, u8 val)
{
	return regmap_raw_write(chip->data.regmap, reg, &val, sizeof(u8));
}

static const struct regmap_config rt1711h_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,

	.max_register = 0xFF, /* 0x80 .. 0xFF are vendor defined */
};

static struct rt1711h_chip *tdata_to_rt1711h(struct tcpci_data *tdata)
{
	return container_of(tdata, struct rt1711h_chip, data);
}

static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata)
{
	struct rt1711h_chip *chip = tdata_to_rt1711h(tdata);
	struct regmap *regmap = chip->data.regmap;
	int ret;

	/* CK 300K from 320K, shipping off, auto_idle enable, tout = 32ms */
	ret = rt1711h_write8(chip, RT1711H_RTCTRL8,
			     RT1711H_RTCTRL8_SET(0, 1, 1, 2));
	if (ret < 0)
		return ret;

	/* Enable PD30 extended message for RT1715 */
	if (chip->info->enable_pd30_extended_message) {
		ret = regmap_update_bits(regmap, RT1711H_RTCTRL8,
					 RT1711H_ENEXTMSG, RT1711H_ENEXTMSG);
		if (ret < 0)
			return ret;
	}

	/* I2C reset : (val + 1) * 12.5ms */
	ret = rt1711h_write8(chip, RT1711H_RTCTRL11,
			     RT1711H_RTCTRL11_SET(1, 0x0F));
	if (ret < 0)
		return ret;

	/* tTCPCfilter : (26.7 * val) us */
	ret = rt1711h_write8(chip, RT1711H_RTCTRL14, 0x0F);
	if (ret < 0)
		return ret;

	/*  tDRP : (51.2 + 6.4 * val) ms */
	ret = rt1711h_write8(chip, RT1711H_RTCTRL15, 0x04);
	if (ret < 0)
		return ret;

	/* dcSRC.DRP : 33% */
	ret = rt1711h_write16(chip, RT1711H_RTCTRL16, 330);
	if (ret < 0)
		return ret;

	/* Enable phy discard retry, retry count 7, rx filter deglitch 100 us */
	ret = rt1711h_write8(chip, RT1711H_PHYCTRL1, 0xF1);
	if (ret < 0)

Annotation

Implementation Notes