Skip to content

Commit

Permalink
r8152: add r8153_phy_status function
Browse files Browse the repository at this point in the history
Use r8153_phy_status() to check phy status of RTL8153.

Signed-off-by: Hayes Wang <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
hayesorz authored and davem330 committed Jun 9, 2017
1 parent a2e8bbd commit c564b87
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions drivers/net/usb/r8152.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@

/* OCP_PHY_STATUS */
#define PHY_STAT_MASK 0x0007
#define PHY_STAT_EXT_INIT 2
#define PHY_STAT_LAN_ON 3
#define PHY_STAT_PWRDN 5

Expand Down Expand Up @@ -2452,6 +2453,28 @@ static void r8153_u2p3en(struct r8152 *tp, bool enable)
ocp_write_word(tp, MCU_TYPE_USB, USB_U2P3_CTRL, ocp_data);
}

static u16 r8153_phy_status(struct r8152 *tp, u16 desired)
{
u16 data;
int i;

for (i = 0; i < 500; i++) {
data = ocp_reg_read(tp, OCP_PHY_STATUS);
data &= PHY_STAT_MASK;
if (desired) {
if (data == desired)
break;
} else if (data == PHY_STAT_LAN_ON || data == PHY_STAT_PWRDN ||
data == PHY_STAT_EXT_INIT) {
break;
}

msleep(20);
}

return data;
}

static void r8153_power_cut_en(struct r8152 *tp, bool enable)
{
u32 ocp_data;
Expand Down Expand Up @@ -3420,12 +3443,7 @@ static void r8153_init(struct r8152 *tp)
msleep(20);
}

for (i = 0; i < 500; i++) {
ocp_data = ocp_reg_read(tp, OCP_PHY_STATUS) & PHY_STAT_MASK;
if (ocp_data == PHY_STAT_LAN_ON || ocp_data == PHY_STAT_PWRDN)
break;
msleep(20);
}
data = r8153_phy_status(tp, 0);

if (tp->version == RTL_VER_03 || tp->version == RTL_VER_04 ||
tp->version == RTL_VER_05)
Expand All @@ -3437,12 +3455,7 @@ static void r8153_init(struct r8152 *tp)
r8152_mdio_write(tp, MII_BMCR, data);
}

for (i = 0; i < 500; i++) {
ocp_data = ocp_reg_read(tp, OCP_PHY_STATUS) & PHY_STAT_MASK;
if (ocp_data == PHY_STAT_LAN_ON)
break;
msleep(20);
}
data = r8153_phy_status(tp, PHY_STAT_LAN_ON);

usb_disable_lpm(tp->udev);
r8153_u2p3en(tp, false);
Expand Down

0 comments on commit c564b87

Please sign in to comment.