From: Florent Kermarrec Date: Fri, 9 Aug 2019 08:31:53 +0000 (+0200) Subject: software/libase/mdio: cleanup and reduce raw_turnaround by 1 cycle X-Git-Tag: 24jan2021_ls180~1056 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6d94c07d70bd2ea7ae6db8958b5ae13131d1af97;p=litex.git software/libase/mdio: cleanup and reduce raw_turnaround by 1 cycle --- diff --git a/litex/soc/software/include/base/mdio.h b/litex/soc/software/include/base/mdio.h index 875e53c5..bffa5a63 100644 --- a/litex/soc/software/include/base/mdio.h +++ b/litex/soc/software/include/base/mdio.h @@ -7,6 +7,12 @@ #define MDIO_DI 0x01 +#define MDIO_PREAMBLE 0xffffffff +#define MDIO_START 0x1 +#define MDIO_READ 0x2 +#define MDIO_WRITE 0x1 +#define MDIO_TURN_AROUND 0x2 + void mdio_write(int phyadr, int reg, int val); int mdio_read(int phyadr, int reg); diff --git a/litex/soc/software/libbase/mdio.c b/litex/soc/software/libbase/mdio.c index 97487348..362e274c 100644 --- a/litex/soc/software/libbase/mdio.c +++ b/litex/soc/software/libbase/mdio.c @@ -7,7 +7,8 @@ static void delay(void) { -/* no delay FIXME */ + volatile int i; + for(i=0;i<100;i++); } static void raw_write(unsigned int word, int bitcount) @@ -54,20 +55,17 @@ static void raw_turnaround(void) delay(); ethphy_mdio_w_write(0); delay(); - ethphy_mdio_w_write(MDIO_CLK); - delay(); - ethphy_mdio_w_write(0); - delay(); } void mdio_write(int phyadr, int reg, int val) { ethphy_mdio_w_write(MDIO_OE); - raw_write(0xffffffff, 32); /* < sync */ - raw_write(0x05, 4); /* < start + write */ + raw_write(MDIO_PREAMBLE, 32); + raw_write(MDIO_START, 2); + raw_write(MDIO_WRITE, 2); raw_write(phyadr, 5); raw_write(reg, 5); - raw_write(0x02, 2); /* < turnaround */ + raw_write(MDIO_TURN_AROUND, 2); raw_write(val, 16); raw_turnaround(); } @@ -77,8 +75,9 @@ int mdio_read(int phyadr, int reg) int r; ethphy_mdio_w_write(MDIO_OE); - raw_write(0xffffffff, 32); /* < sync */ - raw_write(0x06, 4); /* < start + read */ + raw_write(MDIO_PREAMBLE, 32); + raw_write(MDIO_START, 2); + raw_write(MDIO_READ, 2); raw_write(phyadr, 5); raw_write(reg, 5); raw_turnaround();