target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl838x.c
int rtl838x_read_mmd_phy(u32 port, u32 addr, u32 reg, u32 *val)
{
	u32 v;

	mutex_lock(&smi_lock);

	if (rtl838x_smi_wait_op(10000))
		goto timeout;

	sw_w32(1 << port, RTL838X_SMI_ACCESS_PHY_CTRL_0);
	mdelay(10);

	sw_w32_mask(0xffff0000, port << 16, RTL838X_SMI_ACCESS_PHY_CTRL_2);

	v = addr << 16 | reg;
	sw_w32(v, RTL838X_SMI_ACCESS_PHY_CTRL_3);

	/* mmd-access | read | cmd-start */
	v = 1 << 1 | 0 << 2 | 1;
	sw_w32(v, RTL838X_SMI_ACCESS_PHY_CTRL_1);

	if (rtl838x_smi_wait_op(10000))
		goto timeout;

	*val = sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_2) & 0xffff;

	mutex_unlock(&smi_lock);
	return 0;

timeout:
	mutex_unlock(&smi_lock);
	return -ETIMEDOUT;
}
/*
 * Read an mmd register of a PHY
 */
Read an mmd register of a PHY
Read an mmd register of a PHY
int rtl838x_read_mmd_phy(u32 port, u32 addr, u32 reg, u32 *val)
{
	u32 v;
	mutex_lock(&smi_lock);
	if (rtl838x_smi_wait_op(10000))
		goto timeout;
	sw_w32(1 << port, RTL838X_SMI_ACCESS_PHY_CTRL_0);
	mdelay(10);
	sw_w32_mask(0xffff0000, port << 16, RTL838X_SMI_ACCESS_PHY_CTRL_2);
	v = addr << 16 | reg;
	sw_w32(v, RTL838X_SMI_ACCESS_PHY_CTRL_3);
	v = 1 << 1 | 0 << 2 | 1;
	sw_w32(v, RTL838X_SMI_ACCESS_PHY_CTRL_1);
	if (rtl838x_smi_wait_op(10000))
		goto timeout;
	*val = sw_r32(RTL838X_SMI_ACCESS_PHY_CTRL_2) & 0xffff;
	mutex_unlock(&smi_lock);
	return 0;
timeout:
	mutex_unlock(&smi_lock);
	return -ETIMEDOUT;
}
int rtl838x_read_mmd_phy ( u32 port , u32 addr , u32 reg , u32 * val ) { u32 v ; mutex_lock ( & smi_lock ) ; if ( rtl838x_smi_wait_op ( 10000 ) ) goto timeout ; sw_w32 ( 1 << port , RTL838X_SMI_ACCESS_PHY_CTRL_0 ) ; mdelay ( 10 ) ; sw_w32_mask ( 0xffff0000 , port << 16 , RTL838X_SMI_ACCESS_PHY_CTRL_2 ) ; v = addr << 16 | reg ; sw_w32 ( v , RTL838X_SMI_ACCESS_PHY_CTRL_3 ) ; v = 1 << 1 | 0 << 2 | 1 ; sw_w32 ( v , RTL838X_SMI_ACCESS_PHY_CTRL_1 ) ; if ( rtl838x_smi_wait_op ( 10000 ) ) goto timeout ; * val = sw_r32 ( RTL838X_SMI_ACCESS_PHY_CTRL_2 ) & 0xffff ; mutex_unlock ( & smi_lock ) ; return 0 ; timeout : mutex_unlock ( & smi_lock ) ; return - ETIMEDOUT ; }
Read an mmd register of a PHY
Read an mmd register of a PHY
/* mmd-access | read | cmd-start */