Skip to contentSkip to conversation

macb add support for phy gpio interrupt

PATCH Applied Joachim Eastwood 2 participants 5 messages Nov 11, 2012 – Nov 15, 2012

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover macb add support for phy gpio interrupt

Main feature of this patch set is phy gpio interrupt for macb.

There is a couple of concerns about this patch series.
* PHY interrupt support has never been supported with macb before but many board have set phy_irq_pin variable. These board will be swapped over to interrupt handing now and while this should work but one can never be 100% certain.
* at91_ether driver supported interrupt on some PHYs which does not have PHY drivers in phylib or doesn't have interrupt support hooked up.

Patch 1 add interrupt handing to a couple of Davicom PHY that is used on most (all?) Atmel eval boards and was also popular on custom boards.

If the 2nd patch breaks any boards there are 2 possible ways to fix the issue. One would be to go back to polling by setting phy_irq_pin to EINVAL. The other would be add a proper PHY driver with interrupt support for the PHY in question.

I would be grateful if anyone can test the 2 first patches on any AT91 boards that they might have access to. If there is any breakage I am more than willing to help out. Patch series was tested on a custom board with DM9161AEP and AT91RM9200 EMAC.

Last patch in this series is unrelated to the phy stuff. It's is a small fix for macb hw set addr functions when used in at91_ether.

v2: set PHY_HAS_INTERRUPT in phy_driver flags.

Joachim Eastwood (3):
net/phy/davicom: add irq functions to DM9161E and DM9161A net/macb: add support for phy irq via gpio pin net/macb: clear unused address register

 drivers/net/ethernet/cadence/macb.c | 20 +++++++++++++++++++-
 drivers/net/ethernet/cadence/macb.h |  6 ++++++
 drivers/net/phy/davicom.c           |  6 ++++++
 3 files changed, 31 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.0
#1 lore raw

PATCH v2 1/3 net/phy/davicom: add irq functions to DM9161E and DM9161A

Both these PHYs support interrupt generation on IC pin 32.

---
 drivers/net/phy/davicom.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/phy/davicom.c +6 -0
index 81c7bc0..383e833 100644
@@ -150,18 +150,24 @@ static struct phy_driver dm91xx_driver[] = {
 	.name		= "Davicom DM9161E",
 	.phy_id_mask	= 0x0ffffff0,
 	.features	= PHY_BASIC_FEATURES,
+	.flags		= PHY_HAS_INTERRUPT,
 	.config_init	= dm9161_config_init,
 	.config_aneg	= dm9161_config_aneg,
 	.read_status	= genphy_read_status,
+	.ack_interrupt	= dm9161_ack_interrupt,
+	.config_intr	= dm9161_config_intr,
 	.driver		= { .owner = THIS_MODULE,},
 }, {
 	.phy_id		= 0x0181b8a0,
 	.name		= "Davicom DM9161A",
 	.phy_id_mask	= 0x0ffffff0,
 	.features	= PHY_BASIC_FEATURES,
+	.flags		= PHY_HAS_INTERRUPT,
 	.config_init	= dm9161_config_init,
 	.config_aneg	= dm9161_config_aneg,
 	.read_status	= genphy_read_status,
+	.ack_interrupt	= dm9161_ack_interrupt,
+	.config_intr	= dm9161_config_intr,
 	.driver		= { .owner = THIS_MODULE,},
 }, {
 	.phy_id		= 0x00181b80,
Signature · 1 line
1.8.0
#2 lore raw

PATCH v2 2/3 net/macb: add support for phy irq via gpio pin

In reply to Joachim Eastwood
---
 drivers/net/ethernet/cadence/macb.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb.c +11 -1
index 1fac769..ca34efc 100644
@@ -16,6 +16,7 @@
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <linux/init.h>
+#include <linux/gpio.h>
 #include <linux/interrupt.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
@@ -261,7 +262,9 @@ static void macb_handle_link_change(struct net_device *dev)
 static int macb_mii_probe(struct net_device *dev)
 {
 	struct macb *bp = netdev_priv(dev);
+	struct macb_platform_data *pdata;
 	struct phy_device *phydev;
+	int phy_irq;
 	int ret;
 
 	phydev = phy_find_first(bp->mii_bus);
@@ -270,7 +273,14 @@ static int macb_mii_probe(struct net_device *dev)
 		return -1;
 	}
 
-	/* TODO : add pin_irq */
+	pdata = dev_get_platdata(&bp->pdev->dev);
+	if (pdata && gpio_is_valid(pdata->phy_irq_pin)) {
+		ret = devm_gpio_request(&bp->pdev->dev, pdata->phy_irq_pin, "phy int");
+		if (!ret) {
+			phy_irq = gpio_to_irq(pdata->phy_irq_pin);
+			phydev->irq = (phy_irq < 0) ? PHY_POLL : phy_irq;
+		}
+	}
 
 	/* attach the mac to the phy */
 	ret = phy_connect_direct(dev, phydev, &macb_handle_link_change, 0,
Signature · 1 line
1.8.0
#3 lore raw

PATCH v2 3/3 net/macb: clear unused address register

In reply to Joachim Eastwood

Only the first register set is used for matching but we support getting the initial hw addr from any of the registers.

To prevent stale entries and false matches clear unused register sets. This most important for the at91_ether driver where u-boot always uses the 2nd register set.

---
 drivers/net/ethernet/cadence/macb.c | 8 ++++++++
 drivers/net/ethernet/cadence/macb.h | 6 ++++++
 2 files changed, 14 insertions(+)
drivers/net/ethernet/cadence/macb.c +8 -0
index ca34efc..edb2aba 100644
@@ -108,6 +108,14 @@ void macb_set_hwaddr(struct macb *bp)
 	macb_or_gem_writel(bp, SA1B, bottom);
 	top = cpu_to_le16(*((u16 *)(bp->dev->dev_addr + 4)));
 	macb_or_gem_writel(bp, SA1T, top);
+
+	/* Clear unused address register sets */
+	macb_or_gem_writel(bp, SA2B, 0);
+	macb_or_gem_writel(bp, SA2T, 0);
+	macb_or_gem_writel(bp, SA3B, 0);
+	macb_or_gem_writel(bp, SA3T, 0);
+	macb_or_gem_writel(bp, SA4B, 0);
+	macb_or_gem_writel(bp, SA4T, 0);
 }
 EXPORT_SYMBOL_GPL(macb_set_hwaddr);
 
drivers/net/ethernet/cadence/macb.h +6 -0
index 864e380..4414421 100644
@@ -74,6 +74,12 @@
 #define GEM_HRT					0x0084
 #define GEM_SA1B				0x0088
 #define GEM_SA1T				0x008C
+#define GEM_SA2B				0x0090
+#define GEM_SA2T				0x0094
+#define GEM_SA3B				0x0098
+#define GEM_SA3T				0x009C
+#define GEM_SA4B				0x00A0
+#define GEM_SA4T				0x00A4
 #define GEM_OTX					0x0100
 #define GEM_DCFG1				0x0280
 #define GEM_DCFG2				0x0284
Signature · 1 line
1.8.0
maintainer Applied
#4 lore raw
In reply to Joachim Eastwood

From: Joachim Eastwood <[email protected]>
Date: Mon, 12 Nov 2012 00:56:25 +0100

Quoted 1 line

Main feature of this patch set is phy gpio interrupt for macb.

...

Quoted 1 line

Patch series was tested on a custom board with DM9161AEP and AT91RM9200 EMAC.

Applied.

If there are problems found during testing we can fix or revert.