target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl930x.c
int rtl930x_read_mmd_phy(u32 port, u32 devnum, u32 regnum, u32 *val)
{
	int err = 0;
	u32 v;

	mutex_lock(&smi_lock);

	// Set PHY to access
	sw_w32_mask(0xffff << 16, port << 16, RTL930X_SMI_ACCESS_PHY_CTRL_2);

	// Set MMD device number and register to write to
	sw_w32(devnum << 16 | (regnum & 0xffff), RTL930X_SMI_ACCESS_PHY_CTRL_3);

	v = BIT(1) | BIT(0); // MMD-access | EXEC
	sw_w32(v, RTL930X_SMI_ACCESS_PHY_CTRL_1);

	do {
		v = sw_r32(RTL930X_SMI_ACCESS_PHY_CTRL_1);
	} while (v & BIT(0));
	// There is no error-checking via BIT 25 of v, as it does not seem to be set correctly
	*val = (sw_r32(RTL930X_SMI_ACCESS_PHY_CTRL_2) & 0xffff);
	pr_debug("%s: port %d, regnum: %x, val: %x (err %d)\n", __func__, port, regnum, *val, err);

	mutex_unlock(&smi_lock);

	return err;
}
/*
 * Read an mmd register of the PHY
 */
Read an mmd register of the PHY
Read an mmd register of the PHY
int rtl930x_read_mmd_phy(u32 port, u32 devnum, u32 regnum, u32 *val)
{
	int err = 0;
	u32 v;
	mutex_lock(&smi_lock);
	sw_w32_mask(0xffff << 16, port << 16, RTL930X_SMI_ACCESS_PHY_CTRL_2);
	sw_w32(devnum << 16 | (regnum & 0xffff), RTL930X_SMI_ACCESS_PHY_CTRL_3);
	v = BIT(1) | BIT(0); 
	sw_w32(v, RTL930X_SMI_ACCESS_PHY_CTRL_1);
	do {
		v = sw_r32(RTL930X_SMI_ACCESS_PHY_CTRL_1);
	} while (v & BIT(0));
	*val = (sw_r32(RTL930X_SMI_ACCESS_PHY_CTRL_2) & 0xffff);
	pr_debug("%s: port %d, regnum: %x, val: %x (err %d)\n", __func__, port, regnum, *val, err);
	mutex_unlock(&smi_lock);
	return err;
}
int rtl930x_read_mmd_phy ( u32 port , u32 devnum , u32 regnum , u32 * val ) { int err = 0 ; u32 v ; mutex_lock ( & smi_lock ) ; sw_w32_mask ( 0xffff << 16 , port << 16 , RTL930X_SMI_ACCESS_PHY_CTRL_2 ) ; sw_w32 ( devnum << 16 | ( regnum & 0xffff ) , RTL930X_SMI_ACCESS_PHY_CTRL_3 ) ; v = BIT ( 1 ) | BIT ( 0 ) ; sw_w32 ( v , RTL930X_SMI_ACCESS_PHY_CTRL_1 ) ; do { v = sw_r32 ( RTL930X_SMI_ACCESS_PHY_CTRL_1 ) ; } while ( v & BIT ( 0 ) ) ; * val = ( sw_r32 ( RTL930X_SMI_ACCESS_PHY_CTRL_2 ) & 0xffff ) ; pr_debug ( " \n " , __func__ , port , regnum , * val , err ) ; mutex_unlock ( & smi_lock ) ; return err ; }
Read an mmd register of the PHY
Read an mmd register of the PHY
// Set PHY to access // Set MMD device number and register to write to // MMD-access | EXEC // There is no error-checking via BIT 25 of v, as it does not seem to be set correctly