linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Fainelli <florian@openwrt.org>
To: davem@davemloft.net
Cc: Grant Likely <grant.likely@secretlab.ca>,
	Rob Herring <rob.herring@calxeda.com>,
	Rob Landley <rob@landley.net>,
	Jason Cooper <jason@lakedaemon.net>, Andrew Lunn <andrew@lunn.ch>,
	Russell King <linux@arm.linux.org.uk>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Lennert Buytenhek <buytenh@wantstofly.org>,
	Florian Fainelli <florian@openwrt.org>,
	Thomas Petazzoni <thomas.petazzoni@free-electrons.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	devicetree-discuss@lists.ozlabs.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linuxppc-dev@lists.ozlabs.org, netdev@vger.kernel.org
Subject: [PATCH 3/4 v2] net: mvmdio: enhance driver to support SMI error/done interrupts
Date: Thu, 14 Mar 2013 19:08:34 +0100	[thread overview]
Message-ID: <1363284515-9865-4-git-send-email-florian@openwrt.org> (raw)
In-Reply-To: <1363284515-9865-1-git-send-email-florian@openwrt.org>

This patch enhances the "mvmdio" to support a SMI error/done interrupt
line which can be used along with a wait queue instead of doing
busy-waiting on the registers. This is a feature which is available in
the mv643xx_eth SMI code and thus reduces again the gap between the two.

Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
Chances since v1:
- always use orion_smi_is_done() helper
- make interrupt/non-interrupt code path entirely independant

 .../devicetree/bindings/net/marvell-orion-mdio.txt |    3 +
 drivers/net/ethernet/marvell/mvmdio.c              |   83 +++++++++++++++++---
 2 files changed, 74 insertions(+), 12 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/marvell-orion-mdio.txt b/Documentation/devicetree/bindings/net/marvell-orion-mdio.txt
index 34e7aaf..052b5f2 100644
--- a/Documentation/devicetree/bindings/net/marvell-orion-mdio.txt
+++ b/Documentation/devicetree/bindings/net/marvell-orion-mdio.txt
@@ -9,6 +9,9 @@ Required properties:
 - compatible: "marvell,orion-mdio"
 - reg: address and length of the SMI register
 
+Optional properties:
+- interrupts: interrupt line number for the SMI error/done interrupt
+
 The child nodes of the MDIO driver are the individual PHY devices
 connected to this MDIO bus. They must have a "reg" property given the
 PHY address on the MDIO bus.
diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/marvell/mvmdio.c
index 595deea..7ac83de 100644
--- a/drivers/net/ethernet/marvell/mvmdio.c
+++ b/drivers/net/ethernet/marvell/mvmdio.c
@@ -24,9 +24,12 @@
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/phy.h>
+#include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/delay.h>
 #include <linux/io.h>
+#include <linux/sched.h>
+#include <linux/wait.h>
 
 #define MVMDIO_SMI_DATA_SHIFT              0
 #define MVMDIO_SMI_PHY_ADDR_SHIFT          16
@@ -35,33 +38,58 @@
 #define MVMDIO_SMI_WRITE_OPERATION         0
 #define MVMDIO_SMI_READ_VALID              BIT(27)
 #define MVMDIO_SMI_BUSY                    BIT(28)
+#define MVMDIO_ERR_INT_CAUSE		   0x007C
+#define  MVMDIO_ERR_INT_SMI_DONE	   0x00000010
+#define MVMDIO_ERR_INT_MASK		   0x0080
 
 struct orion_mdio_dev {
 	struct mutex lock;
 	void __iomem *regs;
+	/*
+	 * If we have access to the error interrupt pin (which is
+	 * somewhat misnamed as it not only reflects internal errors
+	 * but also reflects SMI completion), use that to wait for
+	 * SMI access completion instead of polling the SMI busy bit.
+	 */
+	int err_interrupt;
+	wait_queue_head_t smi_busy_wait;
 };
 
+static int orion_mdio_smi_is_done(struct orion_mdio_dev *dev)
+{
+	return !(readl(dev->regs) & MVMDIO_SMI_BUSY);
+}
+
 /* Wait for the SMI unit to be ready for another operation
  */
 static int orion_mdio_wait_ready(struct mii_bus *bus)
 {
 	struct orion_mdio_dev *dev = bus->priv;
 	int count;
-	u32 val;
 
-	count = 0;
-	while (1) {
-		val = readl(dev->regs);
-		if (!(val & MVMDIO_SMI_BUSY))
-			break;
+	if (dev->err_interrupt == NO_IRQ) {
+		count = 0;
+		while (1) {
+			if (orion_mdio_smi_is_done(dev))
+				break;
 
-		if (count > 100) {
-			dev_err(bus->parent, "Timeout: SMI busy for too long\n");
-			return -ETIMEDOUT;
-		}
+			if (count > 100) {
+				dev_err(bus->parent,
+					"Timeout: SMI busy for too long\n");
+				return -ETIMEDOUT;
+			}
 
-		udelay(10);
-		count++;
+			udelay(10);
+			count++;
+		}
+	} else {
+		if (!orion_mdio_smi_is_done(dev)) {
+			wait_event_timeout(dev->smi_busy_wait,
+				orion_mdio_smi_is_done(dev),
+				msecs_to_jiffies(100));
+			if (!orion_mdio_smi_is_done(dev))
+				return -ETIMEDOUT;
+		}
 	}
 
 	return 0;
@@ -140,6 +168,21 @@ static int orion_mdio_reset(struct mii_bus *bus)
 	return 0;
 }
 
+static irqreturn_t orion_mdio_err_irq(int irq, void *dev_id)
+{
+	struct orion_mdio_dev *dev = dev_id;
+
+	if (readl(dev->regs + MVMDIO_ERR_INT_CAUSE) &
+			MVMDIO_ERR_INT_SMI_DONE) {
+		writel(~MVMDIO_ERR_INT_SMI_DONE,
+				dev->regs + MVMDIO_ERR_INT_CAUSE);
+		wake_up(&dev->smi_busy_wait);
+		return IRQ_HANDLED;
+	}
+
+	return IRQ_NONE;
+}
+
 static int orion_mdio_probe(struct platform_device *pdev)
 {
 	struct resource *r;
@@ -185,6 +228,19 @@ static int orion_mdio_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
+	init_waitqueue_head(&dev->smi_busy_wait);
+
+	dev->err_interrupt = platform_get_irq(pdev, 0);
+	if (dev->err_interrupt != -ENXIO) {
+		ret = devm_request_irq(&pdev->dev, dev->err_interrupt,
+					orion_mdio_err_irq,
+					IRQF_SHARED, pdev->name, dev);
+		if (!ret)
+			writel(MVMDIO_ERR_INT_SMI_DONE,
+					dev->regs + MVMDIO_ERR_INT_MASK);
+	} else
+		dev->err_interrupt = NO_IRQ;
+
 	mutex_init(&dev->lock);
 
 	ret = mdiobus_register(bus);
@@ -203,6 +259,9 @@ static int orion_mdio_probe(struct platform_device *pdev)
 static int orion_mdio_remove(struct platform_device *pdev)
 {
 	struct mii_bus *bus = platform_get_drvdata(pdev);
+	struct orion_mdio_dev *dev = bus->priv;
+
+	writel(0, dev->regs + MVMDIO_ERR_INT_MASK);
 	mdiobus_unregister(bus);
 	kfree(bus->irq);
 	mdiobus_free(bus);
-- 
1.7.10.4


  parent reply	other threads:[~2013-03-14 18:20 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-29 15:24 [PATCH 0/5] mv643xx_eth: use mvmdio MDIO bus driver Florian Fainelli
2013-01-29 15:24 ` [PATCH 1/5] net: mvmdio: unmap base register address at driver removal Florian Fainelli
2013-01-29 15:32   ` Thomas Petazzoni
2013-01-29 15:35     ` Florian Fainelli
2013-01-29 15:24 ` [PATCH 2/5] net: mvmdio: rename base register cookie from smireg to regs Florian Fainelli
2013-01-29 15:34   ` Thomas Petazzoni
2013-01-29 15:24 ` [PATCH 3/5] net: mvmdio: enhance driver to support SMI error/done interrupts Florian Fainelli
2013-01-29 15:39   ` Thomas Petazzoni
2013-01-29 15:24 ` [PATCH 4/5] net: mvmdio: allow Device Tree and platform device to coexist Florian Fainelli
2013-01-29 15:48   ` Thomas Petazzoni
2013-01-29 17:59   ` Jason Gunthorpe
2013-01-29 20:41     ` Florian Fainelli
2013-01-29 15:24 ` [PATCH 5/5] mv643xx_eth: convert to use the Marvell Orion MDIO driver Florian Fainelli
2013-01-29 16:01   ` Thomas Petazzoni
2013-01-29 16:27     ` Florian Fainelli
2013-01-29 16:46       ` Thomas Petazzoni
2013-01-29 18:13   ` Jason Gunthorpe
2013-01-29 20:41     ` Florian Fainelli
2013-03-14 17:25 ` [PATCH 0/5] mv643xx_eth: use mvmdio MDIO bus driver Jason Cooper
2013-03-14 18:09   ` Florian Fainelli
2013-03-14 18:16     ` Jason Cooper
2013-03-14 18:08 ` [PATCH 0/4] " Florian Fainelli
2013-03-14 18:08   ` [PATCH] mv643xx_eth: convert to use the Marvell Orion MDIO driver Florian Fainelli
2013-03-14 19:02     ` Jason Cooper
2013-03-14 19:32       ` Florian Fainelli
2013-03-14 20:36         ` Jason Cooper
2013-03-14 18:08   ` [PATCH 2/4 v2] net: mvmdio: rename base register cookie from smireg to regs Florian Fainelli
2013-03-14 18:08   ` Florian Fainelli [this message]
2013-03-15 18:05     ` [PATCH 3/4 v2] net: mvmdio: enhance driver to support SMI error/done interrupts Russell King - ARM Linux
2013-03-14 18:08   ` [PATCH 4/4 v2] mv643xx_eth: convert to use the Marvell Orion MDIO driver Florian Fainelli
2013-03-15 11:07     ` Florian Fainelli
2013-03-15 11:42       ` Thomas Petazzoni
2013-03-14 18:11   ` [PATCH 1/4 v2] net: mvmdio: allow platform device style registration Florian Fainelli
2013-03-15 12:53   ` [PATCH 0/4] mv643xx_eth: use mvmdio MDIO bus driver David Miller
2013-03-15 12:51     ` Florian Fainelli
2013-03-15 12:55     ` David Miller
2013-03-15 12:53       ` Florian Fainelli
2013-03-15 13:05         ` David Miller
2013-03-15 13:03           ` Florian Fainelli
2013-03-22 13:39   ` [PATCH 0/4 v3] " Florian Fainelli
2013-03-22 13:39     ` [PATCH 1/4 v3] net: mvmdio: allow platform device style registration Florian Fainelli
2013-03-22 13:39     ` [PATCH 2/4 v3] net: mvmdio: rename base register cookie from smireg to regs Florian Fainelli
2013-03-22 13:39     ` [PATCH 3/4 v3] net: mvmdio: enhance driver to support SMI error/done interrupts Florian Fainelli
2013-03-22 13:39     ` [PATCH 4/4 v3] mv643xx_eth: convert to use the Marvell Orion MDIO driver Florian Fainelli
2013-03-22 13:53     ` [PATCH 0/4 v3] mv643xx_eth: use mvmdio MDIO bus driver Thomas Petazzoni
2013-03-22 14:14     ` Jason Cooper
2013-03-22 14:24       ` Florian Fainelli
2013-03-22 14:29         ` Jason Cooper
2013-03-22 14:31           ` Florian Fainelli
2013-03-22 14:26     ` David Miller

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=1363284515-9865-4-git-send-email-florian@openwrt.org \
    --to=florian@openwrt.org \
    --cc=andrew@lunn.ch \
    --cc=benh@kernel.crashing.org \
    --cc=buytenh@wantstofly.org \
    --cc=davem@davemloft.net \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=grant.likely@secretlab.ca \
    --cc=gregkh@linuxfoundation.org \
    --cc=jason@lakedaemon.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=netdev@vger.kernel.org \
    --cc=paulus@samba.org \
    --cc=rob.herring@calxeda.com \
    --cc=rob@landley.net \
    --cc=thomas.petazzoni@free-electrons.com \
    /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;
as well as URLs for NNTP newsgroup(s).