drivers/phy/realtek/phy-rtk-usb2.c

Source file repositories/reference/linux-study-clean/drivers/phy/realtek/phy-rtk-usb2.c

File Facts

System
Linux kernel
Corpus path
drivers/phy/realtek/phy-rtk-usb2.c
Extension
.c
Size
35607 bytes
Lines
1315
Domain
Driver Families
Bucket
drivers/phy
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 phy_reg {
	void __iomem *reg_wrap_vstatus;
	void __iomem *reg_gusb2phyacc0;
	int vstatus_index;
};

struct phy_data {
	u8 addr;
	u8 data;
};

struct phy_cfg {
	int page0_size;
	struct phy_data page0[MAX_USB_PHY_PAGE0_DATA_SIZE];
	int page1_size;
	struct phy_data page1[MAX_USB_PHY_PAGE1_DATA_SIZE];
	int page2_size;
	struct phy_data page2[MAX_USB_PHY_PAGE2_DATA_SIZE];

	int num_phy;

	bool check_efuse;
	int check_efuse_version;
#define CHECK_EFUSE_V1 1
#define CHECK_EFUSE_V2 2
	int efuse_dc_driving_rate;
	int efuse_dc_disconnect_rate;
	int dc_driving_mask;
	int dc_disconnect_mask;
	bool usb_dc_disconnect_at_page0;
	int driving_updated_for_dev_dis;

	bool do_toggle;
	bool do_toggle_driving;
	bool use_default_parameter;
	bool is_double_sensitivity_mode;
};

struct phy_parameter {
	struct phy_reg phy_reg;

	/* Get from efuse */
	s8 efuse_usb_dc_cal;
	s8 efuse_usb_dc_dis;

	/* Get from dts */
	bool inverse_hstx_sync_clock;
	u32 driving_level;
	s32 driving_level_compensate;
	s32 disconnection_compensate;
};

struct rtk_phy {
	struct device *dev;

	struct phy_cfg *phy_cfg;
	int num_phy;
	struct phy_parameter *phy_parameter;

	struct dentry *debug_dir;
};

/* mapping 0xE0 to 0 ... 0xE7 to 7, 0xF0 to 8 ,,, 0xF7 to 15 */
static inline int page_addr_to_array_index(u8 addr)
{
	return (int)((((addr) - PAGE_START) & 0x7) +
		((((addr) - PAGE_START) & 0x10) >> 1));
}

static inline u8 array_index_to_page_addr(int index)
{
	return ((((index) + PAGE_START) & 0x7) +
		((((index) & 0x8) << 1) + PAGE_START));
}

#define PHY_IO_TIMEOUT_USEC		(50000)
#define PHY_IO_DELAY_US			(100)

static inline int utmi_wait_register(void __iomem *reg, u32 mask, u32 result)
{
	int ret;
	unsigned int val;

	ret = read_poll_timeout(readl, val, ((val & mask) == result),
				PHY_IO_DELAY_US, PHY_IO_TIMEOUT_USEC, false, reg);
	if (ret) {
		pr_err("%s can't program USB phy\n", __func__);
		return -ETIMEDOUT;
	}

Annotation

Implementation Notes