10 mii_discover_phy(void)
13 unsigned short phy_reg;
17 printf("Discovering phy @ 0: ");
18 phy_id = mii_phy_read(2) << 16;
19 phy_id |= mii_phy_read(3);
20 if ((phy_id & 0xFFFFFC00) == 0x00137800) {
22 if ((phy_id & 0x000003F0) == 0xE0) {
23 printf("LXT971A Revision %d\n", (int)(phy_id & 0xF));
26 else printf("unknown type\n");
28 else printf("unknown OUI = 0x%08lX\n", phy_id);
30 phy_reg = mii_phy_read(1);
31 if (!(phy_reg & 0x0004)) printf("Link is down\n");
32 if (!(phy_reg & 0x0020)) printf("Auto-negotiation not complete\n");
33 if (phy_reg & 0x0002) printf("Jabber condition detected\n");
34 if (phy_reg & 0x0010) printf("Remote fault condition detected \n");
37 phy_reg = mii_phy_read(17);
39 printf("Phy operating at %d MBit/s in %s-duplex mode\n",
40 phy_reg & 0x4000 ? 100 : 10,
41 phy_reg & 0x0200 ? "full" : "half");
43 printf("bad link!!\n");
45 left off: no link, green 100MBit, yellow 10MBit
46 right off: no activity, green full-duplex, yellow half-duplex
48 mii_phy_write(20, 0x0452);
53 mii_phy_read(unsigned short reg)
56 unsigned short tmp, val = 0, adr = 0;
57 t_rpx_regs *regs = (t_rpx_regs*)CONFIG_SYS_REGS_BASE;
59 tmp = 0x6002 | (adr << 7) | (reg << 2);
61 for (i = 0; i < 64; i++) {
62 regs->bcsr4 ^= MII_MDCK;
64 for (i = 0; i < 16; i++) {
65 regs->bcsr4 &= ~MII_MDCK;
66 if (tmp & 0x8000) regs->bcsr4 |= MII_MDIO;
67 else regs->bcsr4 &= ~MII_MDIO;
68 regs->bcsr4 |= MII_MDCK;
71 regs->bcsr4 |= MII_MDIR;
72 for (i = 0; i < 16; i++) {
74 regs->bcsr4 = MII_MDIO | (regs->bcsr4 | MII_MDCK);
75 if (regs->bcsr4 & MII_MDIO) val |= 1;
76 regs->bcsr4 = MII_MDIO | (regs->bcsr4 &= ~MII_MDCK);
82 mii_phy_write(unsigned short reg, unsigned short val)
85 unsigned short tmp, adr = 0;
86 t_rpx_regs *regs = (t_rpx_regs*)CONFIG_SYS_REGS_BASE;
88 tmp = 0x5002 | (adr << 7) | (reg << 2);
90 for (i = 0; i < 64; i++) {
91 regs->bcsr4 ^= MII_MDCK;
93 for (i = 0; i < 16; i++) {
94 regs->bcsr4 &= ~MII_MDCK;
95 if (tmp & 0x8000) regs->bcsr4 |= MII_MDIO;
96 else regs->bcsr4 &= ~MII_MDIO;
97 regs->bcsr4 |= MII_MDCK;
100 for (i = 0; i < 16; i++) {
101 regs->bcsr4 &= ~MII_MDCK;
102 if (val & 0x8000) regs->bcsr4 |= MII_MDIO;
103 else regs->bcsr4 &= ~MII_MDIO;
104 regs->bcsr4 |= MII_MDCK;