#include <generated/csr.h>
-#include <base/mdio.h>
+#include "mdio.h"
#include "../command.h"
#include "../helpers.h"
#endif
#ifdef CSR_ETHPHY_MDIO_W_ADDR
-#include <mdio.h>
+#include "mdio.h"
#endif
#include "sdram.h"
+++ /dev/null
-#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 */
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
+++ /dev/null
-#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
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
--- /dev/null
+#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
--- /dev/null
+#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 */