[U-Boot] [RFC PATCH v1 8/9] sparc: Add MDIO support to GRETH driver
Francois Retief
fgretief at spaceteq.co.za
Wed Oct 29 09:53:06 CET 2014
Added MDIO support to the Aeroflex Gaisler GRETH driver. The result is
that we can now use the CONFIG_CMD_MII commands to access the PHY chip.
Signed-off-by: Francois Retief <fgretief at spaceteq.co.za>
---
drivers/net/greth.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/drivers/net/greth.c b/drivers/net/greth.c
index 7784684..5f5abd6 100644
--- a/drivers/net/greth.c
+++ b/drivers/net/greth.c
@@ -18,6 +18,8 @@
#include <asm/processor.h>
#include <ambapp.h>
#include <asm/leon.h>
+#include <miiphy.h>
+#include <errno.h>
#include "greth.h"
@@ -52,6 +54,7 @@ typedef struct {
greth_regs *regs;
int irq;
struct eth_device *dev;
+ struct mii_dev *bus;
/* Hardware info */
unsigned char phyaddr;
@@ -124,6 +127,57 @@ static void write_mii(int phyaddr, int regaddr, int data, volatile greth_regs *
}
+#ifdef CONFIG_MII
+
+static int greth_mdio_read(struct mii_dev *bus, int port_addr, int dev_addr, int regnum)
+{
+ greth_regs *regs = (greth_regs *)bus->priv;
+
+ debug("GRETH: mdio_read (port_addr=%d, dev_addr=%d, reg=%d)\n", port_addr, dev_addr, regnum);
+
+ return read_mii(port_addr, regnum, regs);
+}
+
+static int greth_mdio_write(struct mii_dev *bus, int port_addr, int dev_addr, int regnum, u16 value)
+{
+ greth_regs *regs = (greth_regs *)bus->priv;
+
+ debug("GRETH: mdio_write (port_addr=%d, dev_addr=%d, reg=%d, value=%d)\n", port_addr, dev_addr, regnum, value);
+
+ write_mii(port_addr, regnum, value, regs);
+ return 0;
+}
+
+static int greth_mdio_reset(struct mii_dev *bus)
+{
+ puts("GRETH: Reset PHY via MDIO reset\n");
+ return 0;
+}
+
+int greth_mdio_register(greth_priv *greth, bd_t *bis)
+{
+ struct mii_dev *bus = mdio_alloc();
+
+ if (!bus) {
+ printf("GRETH: Failed to allocate MDIO bus\n");
+ return -ENOMEM;
+ }
+
+ bus->read = greth_mdio_read;
+ bus->write = greth_mdio_write;
+ bus->reset = greth_mdio_reset;
+ sprintf(bus->name, "GRETH%d", 0);
+
+ bus->priv = (void *)greth->regs;
+ greth->bus = bus;
+
+ return mdio_register(bus);
+}
+
+#else
+static inline int greth_mdio_register(greth_priv *greth, bd_t *bis) { return 0; }
+#endif /* CONFIG_CMD_MII */
+
/* init/start hardware and allocate descriptor buffers for rx side
*
*/
@@ -633,6 +687,9 @@ int greth_initialize(bd_t * bis)
sprintf(dev->name, "GRETH_10/100");
}
+ /* Register our device with the MDIO subsystem */
+ greth_mdio_register(greth, bis);
+
/* initiate PHY, select speed/duplex depending on connected PHY */
if (greth_init_phy(greth, bis)) {
/* Failed to init PHY (timedout) */
--
1.9.3
________________________________
Disclaimer and confidentiality note – refer to our website for further details: www.spaceteq.co.za <http://www.spaceteq.co.za/home/emaildisclaimer/>
More information about the U-Boot
mailing list