drivers/phy/mediatek/phy-mtk-tphy.c

Source file repositories/reference/linux-study-clean/drivers/phy/mediatek/phy-mtk-tphy.c

File Facts

System
Linux kernel
Corpus path
drivers/phy/mediatek/phy-mtk-tphy.c
Extension
.c
Size
46878 bytes
Lines
1680
Domain
Driver Families
Bucket
drivers/phy
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern 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

static const struct file_operations u2_phy_fops = {
	.open = u2_phy_params_open,
	.write = u2_phy_params_write,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = single_release,
};

static void u2_phy_dbgfs_files_create(struct mtk_phy_instance *inst)
{
	u32 count = ARRAY_SIZE(u2_phy_files);
	int i;

	for (i = 0; i < count; i++)
		debugfs_create_file_aux_num(u2_phy_files[i], 0644, inst->phy->debugfs,
				    inst, i,  &u2_phy_fops);
}

static int u3_phy_params_show(struct seq_file *sf, void *unused)
{
	struct mtk_phy_instance *inst = sf->private;
	struct u3phy_banks *u3_banks = &inst->u3_banks;
	u32 val = 0;
	u32 max = 0;
	u32 tmp;
	int ret = debugfs_get_aux_num(sf->file);

	switch (ret) {
	case U3P_EFUSE_EN:
		tmp = readl(u3_banks->phyd + U3P_U3_PHYD_RSV);
		val = !!(tmp & P3D_RG_EFUSE_AUTO_LOAD_DIS);
		max = 1;
		break;

	case U3P_EFUSE_INTR:
		tmp = readl(u3_banks->phya + U3P_U3_PHYA_REG0);
		val = FIELD_GET(P3A_RG_IEXT_INTR, tmp);
		max = FIELD_MAX(P3A_RG_IEXT_INTR);
		break;

	case U3P_EFUSE_TX_IMP:
		tmp = readl(u3_banks->phyd + U3P_U3_PHYD_IMPCAL0);
		val = FIELD_GET(P3D_RG_TX_IMPEL, tmp);
		max = FIELD_MAX(P3D_RG_TX_IMPEL);
		break;

	case U3P_EFUSE_RX_IMP:
		tmp = readl(u3_banks->phyd + U3P_U3_PHYD_IMPCAL1);
		val = FIELD_GET(P3D_RG_RX_IMPEL, tmp);
		max = FIELD_MAX(P3D_RG_RX_IMPEL);
		break;

	default:
		seq_printf(sf, "invalid, %d\n", ret);
		break;
	}

	seq_printf(sf, "%s : %d [0, %d]\n", u3_phy_files[ret], val, max);

	return 0;
}

static int u3_phy_params_open(struct inode *inode, struct file *file)
{
	return single_open(file, u3_phy_params_show, inode->i_private);
}

static ssize_t u3_phy_params_write(struct file *file, const char __user *ubuf,
				   size_t count, loff_t *ppos)
{
	struct seq_file *sf = file->private_data;
	struct mtk_phy_instance *inst = sf->private;
	struct u3phy_banks *u3_banks = &inst->u3_banks;
	void __iomem *phyd = u3_banks->phyd;
	ssize_t rc;
	u32 val;
	int ret = debugfs_get_aux_num(sf->file);

	rc = kstrtouint_from_user(ubuf, USER_BUF_LEN(count), 0, &val);
	if (rc)
		return rc;

	switch (ret) {
	case U3P_EFUSE_EN:
		mtk_phy_update_field(phyd + U3P_U3_PHYD_RSV,
				     P3D_RG_EFUSE_AUTO_LOAD_DIS, !!val);
		break;

	case U3P_EFUSE_INTR:
		mtk_phy_update_field(u3_banks->phya + U3P_U3_PHYA_REG0,

Annotation

Implementation Notes