drivers/extcon/extcon-rtk-type-c.c

Source file repositories/reference/linux-study-clean/drivers/extcon/extcon-rtk-type-c.c

File Facts

System
Linux kernel
Corpus path
drivers/extcon/extcon-rtk-type-c.c
Extension
.c
Size
53042 bytes
Lines
1796
Domain
Driver Families
Bucket
drivers/extcon
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 type_c_parameter_fops = {
	.open			= type_c_parameter_open,
	.read			= seq_read,
	.llseek			= seq_lseek,
	.release		= single_release,
};

static int type_c_status_show(struct seq_file *s, void *unused)
{
	struct type_c_data *type_c = s->private;
	unsigned long flags;

	spin_lock_irqsave(&type_c->lock, flags);

	seq_printf(s, "In %s mode %s at %s (cc_status=0x%x)\n",
		   type_c->cc_mode == IN_HOST_MODE ? "host" : "device",
		   type_c->is_attach ? "attach" : "detach",
		   type_c->at_cc1 ? "cc1" : "cc2", type_c->cc_status);

	seq_printf(s, "Read Register (type_c_ctrl_cc1_0=0x%x)\n",
		   readl(type_c->reg_base + 0x0));
	seq_printf(s, "Read Register (type_c_ctrl_cc1_1=0x%x)\n",
		   readl(type_c->reg_base + 0x4));
	seq_printf(s, "Read Register (type_c_ctrl_cc2_0=0x%x)\n",
		   readl(type_c->reg_base + 0x8));
	seq_printf(s, "Read Register (type_c_ctrl_cc2_1=0x%x)\n",
		   readl(type_c->reg_base + 0xc));
	seq_printf(s, "Read Register (type_c_status=0x%x)\n",
		   readl(type_c->reg_base + 0x10));
	seq_printf(s, "Read Register (type_c_ctrl=0x%x)\n",
		   readl(type_c->reg_base + 0x14));

	spin_unlock_irqrestore(&type_c->lock, flags);

	return 0;
}

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

static const struct file_operations type_c_status_fops = {
	.open			= type_c_status_open,
	.read			= seq_read,
	.llseek			= seq_lseek,
	.release		= single_release,
};

static inline void create_debug_files(struct type_c_data *type_c)
{
	type_c->debug_dir = debugfs_create_dir("type_c", usb_debug_root);

	debugfs_create_file("parameter", 0444, type_c->debug_dir, type_c,
			    &type_c_parameter_fops);

	debugfs_create_file("status", 0444, type_c->debug_dir, type_c,
			    &type_c_status_fops);
}

static inline void remove_debug_files(struct type_c_data *type_c)
{
	debugfs_remove_recursive(type_c->debug_dir);
}
#else
static inline void create_debug_files(struct type_c_data *type_c) { }
static inline void remove_debug_files(struct type_c_data *type_c) { }
#endif /* CONFIG_DEBUG_FS */

/* Init and probe */

static inline s8 get_value(s8 value)
{
	return (((s8)value & 0x8) ? (-(s8)(0x7 & value)) : ((s8)(value)));
}

static int __updated_type_c_parameter_by_efuse(struct type_c_data *type_c)
{
	struct type_c_cfg *type_c_cfg = type_c->type_c_cfg;
	struct cc_param *cc_param;
	struct nvmem_cell *cell;
	s8 cc1_4p7k = 0;
	s8 cc1_12k = 0;
	s8 cc1_0p2v = 0;
	s8 cc1_0p8v = 0;
	s8 cc1_2p6v = 0;
	s8 cc1_0p66v = 0;
	s8 cc1_1p23v = 0;
	s8 cc2_4p7k = 0;
	s8 cc2_12k = 0;

Annotation

Implementation Notes