Skip to content

Commit ac244d3

Browse files
hayesorzdavem330
authored andcommitted
r8152: modify the method of accessing PHY
The old method to access PHY is through mdio channel. Replace it with the OCP channel. Signed-off-by: Hayes Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e3fe0b1 commit ac244d3

File tree

1 file changed

+18
-34
lines changed

1 file changed

+18
-34
lines changed

drivers/net/usb/r8152.c

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
#define OCP_EEE_CONFIG1 0x2080
9999
#define OCP_EEE_CONFIG2 0x2092
100100
#define OCP_EEE_CONFIG3 0x2094
101+
#define OCP_BASE_MII 0xa400
101102
#define OCP_EEE_AR 0xa41a
102103
#define OCP_EEE_DATA 0xa41c
103104

@@ -653,7 +654,7 @@ static void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data)
653654
generic_ocp_write(tp, index, byen, sizeof(tmp), &tmp, type);
654655
}
655656

656-
static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
657+
static u16 ocp_reg_read(struct r8152 *tp, u16 addr)
657658
{
658659
u16 ocp_base, ocp_index;
659660

@@ -664,48 +665,31 @@ static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
664665
}
665666

666667
ocp_index = (addr & 0x0fff) | 0xb000;
667-
ocp_write_word(tp, MCU_TYPE_PLA, ocp_index, data);
668+
return ocp_read_word(tp, MCU_TYPE_PLA, ocp_index);
668669
}
669670

670-
static void r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)
671+
static void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data)
671672
{
672-
u32 ocp_data;
673-
int i;
674-
675-
ocp_data = PHYAR_FLAG | ((reg_addr & 0x1f) << 16) |
676-
(value & 0xffff);
677-
678-
ocp_write_dword(tp, MCU_TYPE_PLA, PLA_PHYAR, ocp_data);
673+
u16 ocp_base, ocp_index;
679674

680-
for (i = 20; i > 0; i--) {
681-
udelay(25);
682-
ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_PHYAR);
683-
if (!(ocp_data & PHYAR_FLAG))
684-
break;
675+
ocp_base = addr & 0xf000;
676+
if (ocp_base != tp->ocp_base) {
677+
ocp_write_word(tp, MCU_TYPE_PLA, PLA_OCP_GPHY_BASE, ocp_base);
678+
tp->ocp_base = ocp_base;
685679
}
686-
udelay(20);
680+
681+
ocp_index = (addr & 0x0fff) | 0xb000;
682+
ocp_write_word(tp, MCU_TYPE_PLA, ocp_index, data);
687683
}
688684

689-
static int r8152_mdio_read(struct r8152 *tp, u32 reg_addr)
685+
static inline void r8152_mdio_write(struct r8152 *tp, u32 reg_addr, u32 value)
690686
{
691-
u32 ocp_data;
692-
int i;
693-
694-
ocp_data = (reg_addr & 0x1f) << 16;
695-
ocp_write_dword(tp, MCU_TYPE_PLA, PLA_PHYAR, ocp_data);
696-
697-
for (i = 20; i > 0; i--) {
698-
udelay(25);
699-
ocp_data = ocp_read_dword(tp, MCU_TYPE_PLA, PLA_PHYAR);
700-
if (ocp_data & PHYAR_FLAG)
701-
break;
702-
}
703-
udelay(20);
704-
705-
if (!(ocp_data & PHYAR_FLAG))
706-
return -EAGAIN;
687+
ocp_reg_write(tp, OCP_BASE_MII + reg_addr * 2, value);
688+
}
707689

708-
return (u16)(ocp_data & 0xffff);
690+
static inline int r8152_mdio_read(struct r8152 *tp, u32 reg_addr)
691+
{
692+
return ocp_reg_read(tp, OCP_BASE_MII + reg_addr * 2);
709693
}
710694

711695
static int read_mii_word(struct net_device *netdev, int phy_id, int reg)

0 commit comments

Comments
 (0)