software/libbase/mdio: set data before clock, revert two cycle turnaround and test with different phys

This commit is contained in:
Florent Kermarrec 2019-08-09 13:26:31 +02:00
parent e670cb9176
commit 31bfb54667
1 changed files with 10 additions and 4 deletions

View File

@ -16,15 +16,17 @@ static void raw_write(unsigned int word, int bitcount)
word <<= 32 - bitcount; word <<= 32 - bitcount;
while(bitcount > 0) { while(bitcount > 0) {
if(word & 0x80000000) { if(word & 0x80000000) {
ethphy_mdio_w_write(MDIO_DO|MDIO_OE);
delay();
ethphy_mdio_w_write(MDIO_CLK|MDIO_DO|MDIO_OE); ethphy_mdio_w_write(MDIO_CLK|MDIO_DO|MDIO_OE);
delay(); delay();
ethphy_mdio_w_write(MDIO_DO|MDIO_OE); ethphy_mdio_w_write(MDIO_DO|MDIO_OE);
delay();
} else { } else {
ethphy_mdio_w_write(MDIO_OE);
delay();
ethphy_mdio_w_write(MDIO_CLK|MDIO_OE); ethphy_mdio_w_write(MDIO_CLK|MDIO_OE);
delay(); delay();
ethphy_mdio_w_write(MDIO_OE); ethphy_mdio_w_write(MDIO_OE);
delay();
} }
word <<= 1; word <<= 1;
bitcount--; bitcount--;
@ -39,22 +41,26 @@ static unsigned int raw_read(void)
word = 0; word = 0;
for(i=0;i<16;i++) { for(i=0;i<16;i++) {
word <<= 1; word <<= 1;
if(ethphy_mdio_r_read() & MDIO_DI)
word |= 1;
ethphy_mdio_w_write(MDIO_CLK); ethphy_mdio_w_write(MDIO_CLK);
delay(); delay();
ethphy_mdio_w_write(0); ethphy_mdio_w_write(0);
delay(); delay();
if(ethphy_mdio_r_read() & MDIO_DI)
word |= 1;
} }
return word; return word;
} }
static void raw_turnaround(void) static void raw_turnaround(void)
{ {
delay();
ethphy_mdio_w_write(MDIO_CLK); ethphy_mdio_w_write(MDIO_CLK);
delay(); delay();
ethphy_mdio_w_write(0); ethphy_mdio_w_write(0);
delay(); delay();
ethphy_mdio_w_write(MDIO_CLK);
delay();
ethphy_mdio_w_write(0);
} }
void mdio_write(int phyadr, int reg, int val) void mdio_write(int phyadr, int reg, int val)