mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v3] davinci_emac: follow phylib changes
@ 2012-09-28 16:17 Jan Luebbe
  2012-09-28 16:17 ` [PATCH v3 1/3] davinci_emac: return 0 on successful transmit Jan Luebbe
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Jan Luebbe @ 2012-09-28 16:17 UTC (permalink / raw)
  To: barebox

Since v2 I've changed the platform_data flags to bools (as suggested by
Jean-Christophe).


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 1/3] davinci_emac: return 0 on successful transmit
  2012-09-28 16:17 [PATCH v3] davinci_emac: follow phylib changes Jan Luebbe
@ 2012-09-28 16:17 ` Jan Luebbe
  2012-09-28 16:17 ` [PATCH v3 2/3] davinci_emac: adjust to new phylib framework Jan Luebbe
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Jan Luebbe @ 2012-09-28 16:17 UTC (permalink / raw)
  To: barebox

The _send function should not return the length of the transmitted packet.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
 drivers/net/davinci_emac.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
index 09fcb63..7f39972 100644
--- a/drivers/net/davinci_emac.c
+++ b/drivers/net/davinci_emac.c
@@ -410,7 +410,7 @@ static int davinci_emac_send(struct eth_device *edev, void *packet, int length)
 {
 	struct davinci_emac_priv *priv = (struct davinci_emac_priv *)edev->priv;
 	uint64_t start;
-	int ret_status = -1;
+	int ret_status;
 
 	dev_dbg(priv->dev, "+ emac_send (length %d)\n", length);
 
@@ -437,7 +437,7 @@ static int davinci_emac_send(struct eth_device *edev, void *packet, int length)
 		if (readl(priv->adap_emac + EMAC_TXINTSTATRAW) & 0x01) {
 			/* Acknowledge the TX descriptor */
 			writel(BD_TO_HW(priv->emac_tx_desc), priv->adap_emac + EMAC_TX0CP);
-			ret_status = length;
+			ret_status = 0;
 			break;
 		}
 		if (is_timeout(start, 100 * MSECOND)) {
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 2/3] davinci_emac: adjust to new phylib framework
  2012-09-28 16:17 [PATCH v3] davinci_emac: follow phylib changes Jan Luebbe
  2012-09-28 16:17 ` [PATCH v3 1/3] davinci_emac: return 0 on successful transmit Jan Luebbe
@ 2012-09-28 16:17 ` Jan Luebbe
  2012-09-28 16:17 ` [PATCH v3 3/3] davinci_emac: get rid of mdio wrapper functions Jan Luebbe
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Jan Luebbe @ 2012-09-28 16:17 UTC (permalink / raw)
  To: barebox

Also pass flags using platform_data and remove useless casts from void*.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
 drivers/net/Kconfig        |    2 +-
 drivers/net/davinci_emac.c |   79 ++++++++++++++++++++++++++------------------
 include/net/davinci_emac.h |   10 ++++++
 3 files changed, 57 insertions(+), 34 deletions(-)
 create mode 100644 include/net/davinci_emac.h

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index b0da2c5..b3e5a83 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -48,7 +48,7 @@ config DRIVER_NET_SMC91111
 config DRIVER_NET_DAVINCI_EMAC
 	bool "TI Davinci/OMAP EMAC ethernet driver"
 	depends on ARCH_DAVINCI || ARCH_OMAP3
-	select MIIDEV
+	select PHYLIB
 
 config DRIVER_NET_DM9K
 	bool "Davicom dm9k[E|A|B] ethernet driver"
diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
index 7f39972..91fd226 100644
--- a/drivers/net/davinci_emac.c
+++ b/drivers/net/davinci_emac.c
@@ -43,18 +43,19 @@
 #include <io.h>
 #include <clock.h>
 #include <net.h>
-#include <miidev.h>
 #include <malloc.h>
 #include <init.h>
 #include <asm/mmu.h>
 #include <asm/system.h>
+#include <linux/phy.h>
 #include <mach/emac_defs.h>
+#include <net/davinci_emac.h>
 #include "davinci_emac.h"
 
 struct davinci_emac_priv {
 	struct device_d *dev;
 	struct eth_device edev;
-	struct mii_device miidev;
+	struct mii_bus miibus;
 
 	/* EMAC Addresses */
 	void __iomem *adap_emac; /* = EMAC_BASE_ADDR */
@@ -72,8 +73,10 @@ struct davinci_emac_priv {
 	/* Receive packet buffers */
 	unsigned char *emac_rx_buffers; /* [EMAC_MAX_RX_BUFFERS * (EMAC_MAX_ETHERNET_PKT_SIZE + EMAC_PKT_ALIGN)] */
 
-	/* PHY address for a discovered PHY (0xff - not found) */
-	uint8_t active_phy_addr; /* = 0xff */
+	/* PHY-specific information */
+	phy_interface_t interface;
+	uint8_t phy_addr;
+	uint32_t phy_flags;
 
 	/* mac_addr[0] goes out on the wire first */
 	uint8_t mac_addr[6];
@@ -149,7 +152,6 @@ static int davinci_eth_phy_read(struct davinci_emac_priv *priv, uint8_t phy_addr
 /* Write to a PHY register via MDIO inteface. Blocks until operation is complete. */
 static int davinci_eth_phy_write(struct davinci_emac_priv *priv, uint8_t phy_addr, uint8_t reg_num, uint16_t data)
 {
-
 	while (readl(priv->adap_mdio + EMAC_MDIO_USERACCESS0) & MDIO_USERACCESS0_GO);
 
 	dev_dbg(priv->dev, "emac_phy_write: addr=0x%02x reg=0x%02x data=0x%04x\n",
@@ -167,16 +169,16 @@ static int davinci_eth_phy_write(struct davinci_emac_priv *priv, uint8_t phy_add
 	return 1;
 }
 
-static int davinci_miidev_read(struct mii_device *dev, int addr, int reg)
+static int davinci_miibus_read(struct mii_bus *bus, int addr, int reg)
 {
-	struct davinci_emac_priv *priv = (struct davinci_emac_priv *)dev->edev->priv;
+	struct davinci_emac_priv *priv = bus->priv;
 	uint16_t value = 0;
 	return davinci_eth_phy_read(priv, addr, reg, &value) ? value : -1;
 }
 
-static int davinci_miidev_write(struct mii_device *dev, int addr, int reg, int value)
+static int davinci_miibus_write(struct mii_bus *bus, int addr, int reg, u16 value)
 {
-	struct davinci_emac_priv *priv = (struct davinci_emac_priv *)dev->edev->priv;
+	struct davinci_emac_priv *priv = (struct davinci_emac_priv *)bus->priv;
 	return davinci_eth_phy_write(priv, addr, reg, value) ? 0 : -1;
 }
 
@@ -191,7 +193,7 @@ static int davinci_emac_get_ethaddr(struct eth_device *edev, unsigned char *adr)
  */
 static int davinci_emac_set_ethaddr(struct eth_device *edev, unsigned char *addr)
 {
-	struct davinci_emac_priv *priv = (struct davinci_emac_priv *)edev->priv;
+	struct davinci_emac_priv *priv = edev->priv;
 	int i;
 
 	for (i = 0; i < sizeof(priv->mac_addr); i++)
@@ -207,7 +209,7 @@ static int davinci_emac_init(struct eth_device *edev)
 
 static int davinci_emac_open(struct eth_device *edev)
 {
-	struct davinci_emac_priv *priv = (struct davinci_emac_priv *)edev->priv;
+	struct davinci_emac_priv *priv = edev->priv;
 	uint32_t clkdiv, cnt;
 	void __iomem *rx_desc;
 	unsigned long mac_hi, mac_lo;
@@ -318,16 +320,11 @@ static int davinci_emac_open(struct eth_device *edev)
 	/* Start receive process */
 	writel(BD_TO_HW(priv->emac_rx_desc), priv->adap_emac + EMAC_RX0HDP);
 
-	ret = miidev_wait_aneg(&priv->miidev);
+	ret = phy_device_connect(edev, &priv->miibus, priv->phy_addr, NULL,
+	                         priv->phy_flags, priv->interface);
 	if (ret)
 		return ret;
 
-	ret = miidev_get_status(&priv->miidev);
-	if (ret < 0)
-		return ret;
-
-	miidev_print_status(&priv->miidev);
-
 	dev_dbg(priv->dev, "- emac_open\n");
 
 	return 0;
@@ -378,7 +375,7 @@ static void davinci_eth_ch_teardown(struct davinci_emac_priv *priv, int ch)
 
 static void davinci_emac_halt(struct eth_device *edev)
 {
-	struct davinci_emac_priv *priv = (struct davinci_emac_priv *)edev->priv;
+	struct davinci_emac_priv *priv = edev->priv;
 
 	dev_dbg(priv->dev, "+ emac_halt\n");
 
@@ -408,7 +405,7 @@ static void davinci_emac_halt(struct eth_device *edev)
  */
 static int davinci_emac_send(struct eth_device *edev, void *packet, int length)
 {
-	struct davinci_emac_priv *priv = (struct davinci_emac_priv *)edev->priv;
+	struct davinci_emac_priv *priv = edev->priv;
 	uint64_t start;
 	int ret_status;
 
@@ -455,7 +452,7 @@ static int davinci_emac_send(struct eth_device *edev, void *packet, int length)
  */
 static int davinci_emac_recv(struct eth_device *edev)
 {
-	struct davinci_emac_priv *priv = (struct davinci_emac_priv *)edev->priv;
+	struct davinci_emac_priv *priv = edev->priv;
 	void __iomem *rx_curr_desc, *curr_desc, *tail_desc;
 	unsigned char *pkt;
 	int status, len, ret = -1;
@@ -531,11 +528,19 @@ out:
 
 static int davinci_emac_probe(struct device_d *dev)
 {
+	struct davinci_emac_platform_data *pdata;
 	struct davinci_emac_priv *priv;
 	uint64_t start;
+	uint32_t phy_mask;
 
 	dev_dbg(dev, "+ emac_probe\n");
 
+	if (!dev->platform_data) {
+		dev_err(dev, "no platform_data\n");
+		return -ENODEV;
+	}
+	pdata = dev->platform_data;
+
 	priv = xzalloc(sizeof(*priv));
 	dev->priv = priv;
 
@@ -556,9 +561,6 @@ static int davinci_emac_probe(struct device_d *dev)
 	/* Receive packet buffers */
 	priv->emac_rx_buffers = xmemalign(4096, EMAC_MAX_RX_BUFFERS * (EMAC_MAX_ETHERNET_PKT_SIZE + EMAC_PKT_ALIGN));
 
-	/* PHY address for a discovered PHY (0xff - not found) */
-	priv->active_phy_addr = 0xff;
-
 	priv->edev.priv = priv;
 	priv->edev.init = davinci_emac_init;
 	priv->edev.open = davinci_emac_open;
@@ -573,22 +575,33 @@ static int davinci_emac_probe(struct device_d *dev)
 
 	start = get_time_ns();
 	while (1) {
-		if (readl(priv->adap_mdio + EMAC_MDIO_ALIVE))
+		phy_mask = readl(priv->adap_mdio + EMAC_MDIO_ALIVE);
+		if (phy_mask) {
+			dev_info(dev, "detected phy mask 0x%x\n", phy_mask);
+			phy_mask = ~phy_mask;
 			break;
+		}
 		if (is_timeout(start, 256 * MSECOND)) {
-			dev_err(dev, "No ETH PHY detected!\n");
+			dev_err(dev, "no live phy, scanning all\n");
+			phy_mask = 0;
 			break;
 		}
 	}
 
-	priv->miidev.read = davinci_miidev_read;
-	priv->miidev.write = davinci_miidev_write;
-	priv->miidev.address = 0x01;
-	priv->miidev.flags = MIIDEV_FORCE_LINK;
-	priv->miidev.edev = &priv->edev;
-	priv->miidev.parent = dev;
+	if (pdata->interface_rmii)
+		priv->interface = PHY_INTERFACE_MODE_RMII;
+	else
+		priv->interface = PHY_INTERFACE_MODE_MII;
+	priv->phy_addr = pdata->phy_addr;
+	priv->phy_flags = pdata->force_link ? PHYLIB_FORCE_LINK : 0;
+
+	priv->miibus.read = davinci_miibus_read;
+	priv->miibus.write = davinci_miibus_write;
+	priv->miibus.priv = priv;
+	priv->miibus.parent = dev;
+	priv->miibus.phy_mask = phy_mask;
 
-	mii_register(&priv->miidev);
+	mdiobus_register(&priv->miibus);
 
 	eth_register(&priv->edev);
 
diff --git a/include/net/davinci_emac.h b/include/net/davinci_emac.h
new file mode 100644
index 0000000..caead1f
--- /dev/null
+++ b/include/net/davinci_emac.h
@@ -0,0 +1,10 @@
+#ifndef __NET_DAVINCI_EMAC_H__
+#define __NET_DAVINCI_EMAC_H__
+
+struct davinci_emac_platform_data {
+	int phy_addr;
+	bool force_link;
+	bool interface_rmii;
+};
+
+#endif /* __NET_DAVINCI_EMAC_H__ */
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 3/3] davinci_emac: get rid of mdio wrapper functions
  2012-09-28 16:17 [PATCH v3] davinci_emac: follow phylib changes Jan Luebbe
  2012-09-28 16:17 ` [PATCH v3 1/3] davinci_emac: return 0 on successful transmit Jan Luebbe
  2012-09-28 16:17 ` [PATCH v3 2/3] davinci_emac: adjust to new phylib framework Jan Luebbe
@ 2012-09-28 16:17 ` Jan Luebbe
  2012-09-28 17:40 ` [PATCH v3] davinci_emac: follow phylib changes Jean-Christophe PLAGNIOL-VILLARD
  2012-09-29 10:58 ` Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Jan Luebbe @ 2012-09-28 16:17 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
 drivers/net/davinci_emac.c |   51 +++++++++++++++++---------------------------
 1 file changed, 19 insertions(+), 32 deletions(-)

diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
index 91fd226..7d4dbdc 100644
--- a/drivers/net/davinci_emac.c
+++ b/drivers/net/davinci_emac.c
@@ -122,64 +122,51 @@ static void davinci_eth_mdio_enable(struct davinci_emac_priv *priv)
 	while (readl(priv->adap_mdio + EMAC_MDIO_CONTROL) & MDIO_CONTROL_IDLE);
 }
 
-/* Read a PHY register via MDIO inteface. Returns 1 on success, 0 otherwise */
-static int davinci_eth_phy_read(struct davinci_emac_priv *priv, uint8_t phy_addr, uint8_t reg_num, uint16_t *data)
+static int davinci_miibus_read(struct mii_bus *bus, int addr, int reg)
 {
-	int	tmp;
+	struct davinci_emac_priv *priv = bus->priv;
+	uint16_t value;
+	int tmp;
 
 	while (readl(priv->adap_mdio + EMAC_MDIO_USERACCESS0) & MDIO_USERACCESS0_GO);
 
 	writel(MDIO_USERACCESS0_GO |
 		MDIO_USERACCESS0_WRITE_READ |
-		((reg_num & 0x1f) << 21) |
-		((phy_addr & 0x1f) << 16),
+		((reg & 0x1f) << 21) |
+		((addr & 0x1f) << 16),
 		priv->adap_mdio + EMAC_MDIO_USERACCESS0);
 
 	/* Wait for command to complete */
 	while ((tmp = readl(priv->adap_mdio + EMAC_MDIO_USERACCESS0)) & MDIO_USERACCESS0_GO);
 
 	if (tmp & MDIO_USERACCESS0_ACK) {
-		*data = tmp & 0xffff;
-		dev_dbg(priv->dev, "emac_phy_read: addr=0x%02x reg=0x%02x data=0x%04x\n",
-			   phy_addr, reg_num, *data);
-		return 1;
+		value = tmp & 0xffff;
+		dev_dbg(priv->dev, "davinci_miibus_read: addr=0x%02x reg=0x%02x value=0x%04x\n",
+			   addr, reg, value);
+		return value;
 	}
 
-	*data = -1;
-	return 0;
+	return -1;
 }
 
-/* Write to a PHY register via MDIO inteface. Blocks until operation is complete. */
-static int davinci_eth_phy_write(struct davinci_emac_priv *priv, uint8_t phy_addr, uint8_t reg_num, uint16_t data)
+static int davinci_miibus_write(struct mii_bus *bus, int addr, int reg, u16 value)
 {
+	struct davinci_emac_priv *priv = bus->priv;
 	while (readl(priv->adap_mdio + EMAC_MDIO_USERACCESS0) & MDIO_USERACCESS0_GO);
 
-	dev_dbg(priv->dev, "emac_phy_write: addr=0x%02x reg=0x%02x data=0x%04x\n",
-		   phy_addr, reg_num, data);
+	dev_dbg(priv->dev, "davinci_miibus_write: addr=0x%02x reg=0x%02x value=0x%04x\n",
+		   addr, reg, value);
 	writel(MDIO_USERACCESS0_GO |
 				MDIO_USERACCESS0_WRITE_WRITE |
-				((reg_num & 0x1f) << 21) |
-				((phy_addr & 0x1f) << 16) |
-				(data & 0xffff),
+				((reg & 0x1f) << 21) |
+				((addr & 0x1f) << 16) |
+				(value & 0xffff),
 		priv->adap_mdio + EMAC_MDIO_USERACCESS0);
 
 	/* Wait for command to complete */
 	while (readl(priv->adap_mdio + EMAC_MDIO_USERACCESS0) & MDIO_USERACCESS0_GO);
 
-	return 1;
-}
-
-static int davinci_miibus_read(struct mii_bus *bus, int addr, int reg)
-{
-	struct davinci_emac_priv *priv = bus->priv;
-	uint16_t value = 0;
-	return davinci_eth_phy_read(priv, addr, reg, &value) ? value : -1;
-}
-
-static int davinci_miibus_write(struct mii_bus *bus, int addr, int reg, u16 value)
-{
-	struct davinci_emac_priv *priv = (struct davinci_emac_priv *)bus->priv;
-	return davinci_eth_phy_write(priv, addr, reg, value) ? 0 : -1;
+	return 0;
 }
 
 static int davinci_emac_get_ethaddr(struct eth_device *edev, unsigned char *adr)
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] davinci_emac: follow phylib changes
  2012-09-28 16:17 [PATCH v3] davinci_emac: follow phylib changes Jan Luebbe
                   ` (2 preceding siblings ...)
  2012-09-28 16:17 ` [PATCH v3 3/3] davinci_emac: get rid of mdio wrapper functions Jan Luebbe
@ 2012-09-28 17:40 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-09-29 10:58 ` Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-09-28 17:40 UTC (permalink / raw)
  To: Jan Luebbe; +Cc: barebox

On 18:17 Fri 28 Sep     , Jan Luebbe wrote:
> Since v2 I've changed the platform_data flags to bools (as suggested by
> Jean-Christophe).
Acked-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>

much more clean specially compare to the U-Boot one

Best Regards,
J.
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3] davinci_emac: follow phylib changes
  2012-09-28 16:17 [PATCH v3] davinci_emac: follow phylib changes Jan Luebbe
                   ` (3 preceding siblings ...)
  2012-09-28 17:40 ` [PATCH v3] davinci_emac: follow phylib changes Jean-Christophe PLAGNIOL-VILLARD
@ 2012-09-29 10:58 ` Sascha Hauer
  4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-09-29 10:58 UTC (permalink / raw)
  To: Jan Luebbe; +Cc: barebox

On Fri, Sep 28, 2012 at 06:17:43PM +0200, Jan Luebbe wrote:
> Since v2 I've changed the platform_data flags to bools (as suggested by
> Jean-Christophe).

Applied, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-09-29 10:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-28 16:17 [PATCH v3] davinci_emac: follow phylib changes Jan Luebbe
2012-09-28 16:17 ` [PATCH v3 1/3] davinci_emac: return 0 on successful transmit Jan Luebbe
2012-09-28 16:17 ` [PATCH v3 2/3] davinci_emac: adjust to new phylib framework Jan Luebbe
2012-09-28 16:17 ` [PATCH v3 3/3] davinci_emac: get rid of mdio wrapper functions Jan Luebbe
2012-09-28 17:40 ` [PATCH v3] davinci_emac: follow phylib changes Jean-Christophe PLAGNIOL-VILLARD
2012-09-29 10:58 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox