From: Florent Kermarrec Date: Mon, 18 May 2020 19:09:41 +0000 (+0200) Subject: software/bios: move mdio to libliteeth. X-Git-Tag: 24jan2021_ls180~328^2~8 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ff8d9e61bf893dba6170722d0e7b6730d8f1c07d;p=litex.git software/bios: move mdio to libliteeth. --- diff --git a/litex/soc/software/bios/commands/cmd_mdio.c b/litex/soc/software/bios/commands/cmd_mdio.c index 35b02073..86e8fc8a 100644 --- a/litex/soc/software/bios/commands/cmd_mdio.c +++ b/litex/soc/software/bios/commands/cmd_mdio.c @@ -5,7 +5,7 @@ #include -#include +#include "mdio.h" #include "../command.h" #include "../helpers.h" diff --git a/litex/soc/software/bios/main.c b/litex/soc/software/bios/main.c index a9857c88..2379dbee 100644 --- a/litex/soc/software/bios/main.c +++ b/litex/soc/software/bios/main.c @@ -38,7 +38,7 @@ #endif #ifdef CSR_ETHPHY_MDIO_W_ADDR -#include +#include "mdio.h" #endif #include "sdram.h" diff --git a/litex/soc/software/include/base/mdio.h b/litex/soc/software/include/base/mdio.h deleted file mode 100644 index bffa5a63..00000000 --- a/litex/soc/software/include/base/mdio.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __MDIO_H -#define __MDIO_H - -#define MDIO_CLK 0x01 -#define MDIO_OE 0x02 -#define MDIO_DO 0x04 - -#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); - -#endif /* __MDIO_H */ diff --git a/litex/soc/software/libbase/Makefile b/litex/soc/software/libbase/Makefile index 13680ad0..55380d8e 100755 --- a/litex/soc/software/libbase/Makefile +++ b/litex/soc/software/libbase/Makefile @@ -2,7 +2,7 @@ include ../include/generated/variables.mak include $(SOC_DIRECTORY)/software/common.mak OBJECTS=exception.o libc.o errno.o crc16.o crc32.o console.o \ - system.o id.o uart.o time.o qsort.o strtod.o spiflash.o spisdcard.o strcasecmp.o mdio.o + system.o id.o uart.o time.o qsort.o strtod.o spiflash.o spisdcard.o strcasecmp.o all: crt0-ctr.o crt0-xip.o libbase.a libbase-nofloat.a diff --git a/litex/soc/software/libbase/mdio.c b/litex/soc/software/libbase/mdio.c deleted file mode 100644 index 770c25e9..00000000 --- a/litex/soc/software/libbase/mdio.c +++ /dev/null @@ -1,96 +0,0 @@ -#include -#ifdef CSR_ETHPHY_MDIO_W_ADDR -#include "mdio.h" - -#include -#include - -static void delay(void) -{ - volatile int i; - for(i=0;i<100;i++); -} - -static void raw_write(unsigned int word, int bitcount) -{ - word <<= 32 - bitcount; - while(bitcount > 0) { - if(word & 0x80000000) { - ethphy_mdio_w_write(MDIO_DO|MDIO_OE); - delay(); - ethphy_mdio_w_write(MDIO_CLK|MDIO_DO|MDIO_OE); - delay(); - ethphy_mdio_w_write(MDIO_DO|MDIO_OE); - } else { - ethphy_mdio_w_write(MDIO_OE); - delay(); - ethphy_mdio_w_write(MDIO_CLK|MDIO_OE); - delay(); - ethphy_mdio_w_write(MDIO_OE); - } - word <<= 1; - bitcount--; - } -} - -static unsigned int raw_read(void) -{ - unsigned int word; - unsigned int i; - - word = 0; - for(i=0;i<16;i++) { - word <<= 1; - if(ethphy_mdio_r_read() & MDIO_DI) - word |= 1; - ethphy_mdio_w_write(MDIO_CLK); - delay(); - ethphy_mdio_w_write(0); - delay(); - } - return word; -} - -static void raw_turnaround(void) -{ - delay(); - ethphy_mdio_w_write(MDIO_CLK); - delay(); - ethphy_mdio_w_write(0); - delay(); - ethphy_mdio_w_write(MDIO_CLK); - delay(); - ethphy_mdio_w_write(0); -} - -void mdio_write(int phyadr, int reg, int val) -{ - ethphy_mdio_w_write(MDIO_OE); - 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(MDIO_TURN_AROUND, 2); - raw_write(val, 16); - raw_turnaround(); -} - -int mdio_read(int phyadr, int reg) -{ - int r; - - ethphy_mdio_w_write(MDIO_OE); - 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(); - r = raw_read(); - raw_turnaround(); - - return r; -} - -#endif \ No newline at end of file diff --git a/litex/soc/software/libliteeth/Makefile b/litex/soc/software/libliteeth/Makefile index 593acc20..c3cf0b98 100644 --- a/litex/soc/software/libliteeth/Makefile +++ b/litex/soc/software/libliteeth/Makefile @@ -1,7 +1,7 @@ include ../include/generated/variables.mak include $(SOC_DIRECTORY)/software/common.mak -OBJECTS=udp.o tftp.o +OBJECTS=udp.o tftp.o mdio.o all: libliteeth.a diff --git a/litex/soc/software/libliteeth/mdio.c b/litex/soc/software/libliteeth/mdio.c new file mode 100644 index 00000000..770c25e9 --- /dev/null +++ b/litex/soc/software/libliteeth/mdio.c @@ -0,0 +1,96 @@ +#include +#ifdef CSR_ETHPHY_MDIO_W_ADDR +#include "mdio.h" + +#include +#include + +static void delay(void) +{ + volatile int i; + for(i=0;i<100;i++); +} + +static void raw_write(unsigned int word, int bitcount) +{ + word <<= 32 - bitcount; + while(bitcount > 0) { + if(word & 0x80000000) { + ethphy_mdio_w_write(MDIO_DO|MDIO_OE); + delay(); + ethphy_mdio_w_write(MDIO_CLK|MDIO_DO|MDIO_OE); + delay(); + ethphy_mdio_w_write(MDIO_DO|MDIO_OE); + } else { + ethphy_mdio_w_write(MDIO_OE); + delay(); + ethphy_mdio_w_write(MDIO_CLK|MDIO_OE); + delay(); + ethphy_mdio_w_write(MDIO_OE); + } + word <<= 1; + bitcount--; + } +} + +static unsigned int raw_read(void) +{ + unsigned int word; + unsigned int i; + + word = 0; + for(i=0;i<16;i++) { + word <<= 1; + if(ethphy_mdio_r_read() & MDIO_DI) + word |= 1; + ethphy_mdio_w_write(MDIO_CLK); + delay(); + ethphy_mdio_w_write(0); + delay(); + } + return word; +} + +static void raw_turnaround(void) +{ + delay(); + ethphy_mdio_w_write(MDIO_CLK); + delay(); + ethphy_mdio_w_write(0); + delay(); + ethphy_mdio_w_write(MDIO_CLK); + delay(); + ethphy_mdio_w_write(0); +} + +void mdio_write(int phyadr, int reg, int val) +{ + ethphy_mdio_w_write(MDIO_OE); + 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(MDIO_TURN_AROUND, 2); + raw_write(val, 16); + raw_turnaround(); +} + +int mdio_read(int phyadr, int reg) +{ + int r; + + ethphy_mdio_w_write(MDIO_OE); + 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(); + r = raw_read(); + raw_turnaround(); + + return r; +} + +#endif \ No newline at end of file diff --git a/litex/soc/software/libliteeth/mdio.h b/litex/soc/software/libliteeth/mdio.h new file mode 100644 index 00000000..bffa5a63 --- /dev/null +++ b/litex/soc/software/libliteeth/mdio.h @@ -0,0 +1,19 @@ +#ifndef __MDIO_H +#define __MDIO_H + +#define MDIO_CLK 0x01 +#define MDIO_OE 0x02 +#define MDIO_DO 0x04 + +#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); + +#endif /* __MDIO_H */