software/bios: move mdio to libliteeth.
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Mon, 18 May 2020 19:09:41 +0000 (21:09 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Mon, 18 May 2020 19:09:41 +0000 (21:09 +0200)
litex/soc/software/bios/commands/cmd_mdio.c
litex/soc/software/bios/main.c
litex/soc/software/include/base/mdio.h [deleted file]
litex/soc/software/libbase/Makefile
litex/soc/software/libbase/mdio.c [deleted file]
litex/soc/software/libliteeth/Makefile
litex/soc/software/libliteeth/mdio.c [new file with mode: 0644]
litex/soc/software/libliteeth/mdio.h [new file with mode: 0644]

index 35b0207378d12179e9ade44e2bb7e8cb72e98298..86e8fc8a945cf8db3ffe5941386ace947c72a341 100644 (file)
@@ -5,7 +5,7 @@
 
 #include <generated/csr.h>
 
-#include <base/mdio.h>
+#include "mdio.h"
 
 #include "../command.h"
 #include "../helpers.h"
index a9857c88d8c56360fc9683c86b1b4249ffd1b7b4..2379dbee26a9dc0bad5bfe1cd86f32f4043cb419 100644 (file)
@@ -38,7 +38,7 @@
 #endif
 
 #ifdef CSR_ETHPHY_MDIO_W_ADDR
-#include <mdio.h>
+#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 (file)
index bffa5a6..0000000
+++ /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 */
index 13680ad0e464aa45b813cdba7416b45d30b7f407..55380d8e79ee4942cee703d70bcbbb47bf2bc713 100755 (executable)
@@ -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 (file)
index 770c25e..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-#include <generated/csr.h>
-#ifdef CSR_ETHPHY_MDIO_W_ADDR
-#include "mdio.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-
-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
index 593acc20332b865f3cc9e7df569aee74f548f87b..c3cf0b98f5f107fd9693edada945052ae6e84658 100644 (file)
@@ -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 (file)
index 0000000..770c25e
--- /dev/null
@@ -0,0 +1,96 @@
+#include <generated/csr.h>
+#ifdef CSR_ETHPHY_MDIO_W_ADDR
+#include "mdio.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+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 (file)
index 0000000..bffa5a6
--- /dev/null
@@ -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 */