I have checked out my "bug report" a little more closely. The original ePHY_init routine was written with only the52259EVB board in mind. This board uses a different PHY compared to the DEMO board. Both PHYs have a different register set, which means that the init routine for the EVB may not work for the DEMO board.
So I made a modification to make the init routine compatible with both EVB and DEMO boards, based on the board selection in processor.h
The first piece of code shows the original code from the init routine, the second piece is my new version.
while(!(fec_mii_read(FEC_PHY0, 0x10, ®0))) // read PHY status register
{
reg0=0;
};
DUPLEX_phy_r17_dpm = (int)((reg0&0x0004)>>2); // 1=full,0=half duplex...used in ifec.c
do //FSL read PHY status register
{
fec_mii_read(FEC_PHY0, 0x10, ®0);
}while (!(reg0&(PHY_R1_LS))); //FSL exit while loop when Link Status up
I still believe the original code contains a bug, by the way. There is a reference to a bit called PHY_R1_LS (link status) in PHY register 0x10.The link status bit is available in register 0x10, but not at the bit position PHY_R1_LS, which actually belongs to the PHY basic status register at adress 0x01.
do //FSL read PHY status register
{
fec_mii_read(FEC_PHY0, PHY_REG_SR, ®0);
}while (!(reg0&(PHY_R1_LS))); //FSL exit while loop when Link Status up
#if M52259EVB
while(!(fec_mii_read(FEC_PHY0, 0x10, ®0))) // read DP83640 PHY status register
{
reg0=0;
};
DUPLEX_phy_r17_dpm = (int)((reg0&0x0004)>>2); // 1=full,0=half duplex...used in ifec.c
#else // M52259DEMO
while ((reg0 & 0x1c) == 0)
{
while(!(fec_mii_read(FEC_PHY0, 0x1f, ®0))) // read KSZ8041NL PHY control 2 register
{
reg0=0;
};
};
DUPLEX_phy_r17_dpm = (int)((reg0&0x0010)>>4); // 1=full,0=half duplex...used in ifec.c
#endif
In my new version, I switched the link status detect and the full/half duplex readout. I think it makes more sense to wait for the link to become active before figuring out if the link is full or half duplex.
Checking the duplex had to be done differently in the EVB and DEMO boards because of the different PHY chips used. See the corrsponding data sheets for th actual registers/bits used.
- Marc