From: Franck Jullien <franck.jullien@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH] drivers/net/ethoc: add mdio bus support
Date: Wed, 14 May 2014 18:59:29 +0200 [thread overview]
Message-ID: <1400086769-31300-1-git-send-email-franck.jullien@gmail.com> (raw)
Signed-off-by: Franck Jullien <franck.jullien@gmail.com>
---
drivers/net/Kconfig | 1 +
drivers/net/ethoc.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 057abd2..7a0d5e1 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -80,6 +80,7 @@ config DRIVER_NET_EP93XX
config DRIVER_NET_ETHOC
bool "OpenCores ethernet MAC driver"
+ select PHYLIB
help
This option enables support for the OpenCores 10/100 Mbps
Ethernet MAC core.
diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c
index b000875..1fb6111 100644
--- a/drivers/net/ethoc.c
+++ b/drivers/net/ethoc.c
@@ -178,6 +178,8 @@ struct ethoc {
u32 num_rx;
u32 cur_rx;
+
+ struct mii_bus miibus;
};
/**
@@ -481,6 +483,54 @@ static int ethoc_send_packet(struct eth_device *edev, void *packet, int length)
return 0;
}
+static int ethoc_mdio_read(struct mii_bus *bus, int phy, int reg)
+{
+ struct ethoc *priv = bus->priv;
+ u64 start;
+ u32 data;
+
+ ethoc_write(priv, MIIADDRESS, MIIADDRESS_ADDR(phy, reg));
+ ethoc_write(priv, MIICOMMAND, MIICOMMAND_READ);
+
+ start = get_time_ns();
+ while (ethoc_read(priv, MIISTATUS) & MIISTATUS_BUSY) {
+ if (is_timeout(start, 2 * MSECOND)) {
+ dev_err(bus->parent, "PHY command timeout\n");
+ return -EBUSY;
+ }
+ }
+
+ data = ethoc_read(priv, MIIRX_DATA);
+
+ /* reset MII command register */
+ ethoc_write(priv, MIICOMMAND, 0);
+
+ return data;
+}
+
+static int ethoc_mdio_write(struct mii_bus *bus, int phy, int reg, u16 val)
+{
+ struct ethoc *priv = bus->priv;
+ u64 start;
+
+ ethoc_write(priv, MIIADDRESS, MIIADDRESS_ADDR(phy, reg));
+ ethoc_write(priv, MIITX_DATA, val);
+ ethoc_write(priv, MIICOMMAND, MIICOMMAND_WRITE);
+
+ start = get_time_ns();
+ while (ethoc_read(priv, MIISTATUS) & MIISTATUS_BUSY) {
+ if (is_timeout(start, 2 * MSECOND)) {
+ dev_err(bus->parent, "PHY command timeout\n");
+ return -EBUSY;
+ }
+ }
+
+ /* reset MII command register */
+ ethoc_write(priv, MIICOMMAND, 0);
+
+ return 0;
+}
+
static int ethoc_probe(struct device_d *dev)
{
struct eth_device *edev;
@@ -493,6 +543,11 @@ static int ethoc_probe(struct device_d *dev)
priv = edev->priv;
priv->iobase = dev_request_mem_region(dev, 0);
+ priv->miibus.read = ethoc_mdio_read;
+ priv->miibus.write = ethoc_mdio_write;
+ priv->miibus.priv = priv;
+ priv->miibus.parent = dev;
+
edev->init = ethoc_init_dev;
edev->open = ethoc_open;
edev->send = ethoc_send_packet;
@@ -503,6 +558,8 @@ static int ethoc_probe(struct device_d *dev)
edev->set_ethaddr = ethoc_set_ethaddr;
edev->parent = dev;
+ mdiobus_register(&priv->miibus);
+
eth_register(edev);
return 0;
--
1.7.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next reply other threads:[~2014-05-14 16:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-14 16:59 Franck Jullien [this message]
2014-05-16 6:03 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1400086769-31300-1-git-send-email-franck.jullien@gmail.com \
--to=franck.jullien@gmail.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox