All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Mark A. Greer" <mgreer@animalcreek.com>
To: paul@pwsan.com, khilman@ti.com
Cc: linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org,
	davinci-linux-open-source@linux.davincidsp.com
Subject: [RFC] net: ethernet: davinci_emac: add pm_runtime support
Date: Fri, 11 May 2012 14:18:45 -0700	[thread overview]
Message-ID: <20120511211845.GA10670@animalcreek.com> (raw)
In-Reply-To: <1336770778-23044-1-git-send-email-mgreer@animalcreek.com>

From: "Mark A. Greer" <mgreer@animalcreek.com>

Add pm_runtime support to the TI Davinci EMAC driver.

Signed-off-by: Mark A. Greer <mgreer@animalcreek.com>
---

This patch is RFC only since it will break emac support
for mach-davinci platforms.  Hopefully, mach-davinci will
be fixed soon and this can be submitted.

 drivers/net/ethernet/ti/davinci_emac.c |   43 ++++++++++++++++----------------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/drivers/net/ethernet/ti/davinci_emac.c b/drivers/net/ethernet/ti/davinci_emac.c
index 174a334..15c84e4 100644
--- a/drivers/net/ethernet/ti/davinci_emac.c
+++ b/drivers/net/ethernet/ti/davinci_emac.c
@@ -57,6 +57,7 @@
 #include <linux/bitops.h>
 #include <linux/io.h>
 #include <linux/uaccess.h>
+#include <linux/pm_runtime.h>
 #include <linux/davinci_emac.h>
 
 #include <asm/irq.h>
@@ -346,10 +347,6 @@ struct emac_priv {
 	void (*int_disable) (void);
 };
 
-/* clock frequency for EMAC */
-static struct clk *emac_clk;
-static unsigned long emac_bus_frequency;
-
 /* EMAC TX Host Error description strings */
 static char *emac_txhost_errcodes[16] = {
 	"No error", "SOP error", "Ownership bit not set in SOP buffer",
@@ -1534,6 +1531,8 @@ static int emac_dev_open(struct net_device *ndev)
 	int k = 0;
 	struct emac_priv *priv = netdev_priv(ndev);
 
+	pm_runtime_get(&priv->pdev->dev);
+
 	netif_carrier_off(ndev);
 	for (cnt = 0; cnt < ETH_ALEN; cnt++)
 		ndev->dev_addr[cnt] = priv->mac_addr[cnt];
@@ -1603,7 +1602,7 @@ static int emac_dev_open(struct net_device *ndev)
 				priv->phy_id);
 			ret = PTR_ERR(priv->phydev);
 			priv->phydev = NULL;
-			return ret;
+			goto err;
 		}
 
 		priv->link = 0;
@@ -1644,7 +1643,11 @@ rollback:
 		res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, k-1);
 		m = res->end;
 	}
-	return -EBUSY;
+
+	ret = -EBUSY;
+err:
+	pm_runtime_put(&priv->pdev->dev);
+	return ret;
 }
 
 /**
@@ -1686,6 +1689,7 @@ static int emac_dev_stop(struct net_device *ndev)
 	if (netif_msg_drv(priv))
 		dev_notice(emac_dev, "DaVinci EMAC: %s stopped\n", ndev->name);
 
+	pm_runtime_put(&priv->pdev->dev);
 	return 0;
 }
 
@@ -1779,6 +1783,9 @@ static int __devinit davinci_emac_probe(struct platform_device *pdev)
 	struct emac_platform_data *pdata;
 	struct device *emac_dev;
 	struct cpdma_params dma_params;
+	struct clk *emac_clk;
+	unsigned long emac_bus_frequency;
+
 
 	/* obtain emac clock from kernel */
 	emac_clk = clk_get(&pdev->dev, NULL);
@@ -1787,12 +1794,14 @@ static int __devinit davinci_emac_probe(struct platform_device *pdev)
 		return -EBUSY;
 	}
 	emac_bus_frequency = clk_get_rate(emac_clk);
+	clk_put(emac_clk);
+
 	/* TODO: Probe PHY here if possible */
 
 	ndev = alloc_etherdev(sizeof(struct emac_priv));
 	if (!ndev) {
 		rc = -ENOMEM;
-		goto free_clk;
+		goto no_ndev;
 	}
 
 	platform_set_drvdata(pdev, ndev);
@@ -1908,15 +1917,13 @@ static int __devinit davinci_emac_probe(struct platform_device *pdev)
 	SET_ETHTOOL_OPS(ndev, &ethtool_ops);
 	netif_napi_add(ndev, &priv->napi, emac_poll, EMAC_POLL_WEIGHT);
 
-	clk_enable(emac_clk);
-
 	/* register the network device */
 	SET_NETDEV_DEV(ndev, &pdev->dev);
 	rc = register_netdev(ndev);
 	if (rc) {
 		dev_err(&pdev->dev, "error in register_netdev\n");
 		rc = -ENODEV;
-		goto netdev_reg_err;
+		goto no_irq_res;
 	}
 
 
@@ -1925,10 +1932,12 @@ static int __devinit davinci_emac_probe(struct platform_device *pdev)
 			   "(regs: %p, irq: %d)\n",
 			   (void *)priv->emac_base_phys, ndev->irq);
 	}
+
+	pm_runtime_enable(&pdev->dev);
+	pm_runtime_resume(&pdev->dev);
+
 	return 0;
 
-netdev_reg_err:
-	clk_disable(emac_clk);
 no_irq_res:
 	if (priv->txchan)
 		cpdma_chan_destroy(priv->txchan);
@@ -1942,8 +1951,7 @@ no_dma:
 
 probe_quit:
 	free_netdev(ndev);
-free_clk:
-	clk_put(emac_clk);
+no_ndev:
 	return rc;
 }
 
@@ -1977,9 +1985,6 @@ static int __devexit davinci_emac_remove(struct platform_device *pdev)
 	iounmap(priv->remap_addr);
 	free_netdev(ndev);
 
-	clk_disable(emac_clk);
-	clk_put(emac_clk);
-
 	return 0;
 }
 
@@ -1991,8 +1996,6 @@ static int davinci_emac_suspend(struct device *dev)
 	if (netif_running(ndev))
 		emac_dev_stop(ndev);
 
-	clk_disable(emac_clk);
-
 	return 0;
 }
 
@@ -2001,8 +2004,6 @@ static int davinci_emac_resume(struct device *dev)
 	struct platform_device *pdev = to_platform_device(dev);
 	struct net_device *ndev = platform_get_drvdata(pdev);
 
-	clk_enable(emac_clk);
-
 	if (netif_running(ndev))
 		emac_dev_open(ndev);
 
-- 
1.7.9.4


  parent reply	other threads:[~2012-05-11 21:18 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-11 21:12 [PATCH 0/2] arm: omap3: am35x: Convert emac to hwmod & disable hlt when open Mark A. Greer
2012-05-11 21:12 ` Mark A. Greer
2012-05-11 21:12 ` [PATCH 1/2] arm: omap3: am35x: Add Davinci EMAC/MDIO hwmod support Mark A. Greer
2012-05-11 21:12   ` Mark A. Greer
2012-05-11 21:12 ` [PATCH 2/2] arm: omap3: am35x: Disable hlt when using Davinci EMAC Mark A. Greer
2012-05-11 21:12   ` Mark A. Greer
2012-05-14  8:20   ` Igor Grinberg
2012-05-14  8:20     ` Igor Grinberg
2012-05-14 16:54     ` Mark A. Greer
2012-05-14 16:54       ` Mark A. Greer
2012-05-14 21:32       ` Kevin Hilman
2012-05-14 21:32         ` Kevin Hilman
2012-05-15 12:42         ` Igor Grinberg
2012-05-15 12:42           ` Igor Grinberg
2012-05-15 16:14           ` Mark A. Greer
2012-05-15 16:14             ` Mark A. Greer
2012-07-18  3:54   ` Paul Walmsley
2012-07-18  3:54     ` Paul Walmsley
2012-07-18 21:32     ` Mark A. Greer
2012-07-18 21:32       ` Mark A. Greer
2012-07-18 23:25       ` Paul Walmsley
2012-07-18 23:25         ` Paul Walmsley
2012-07-19 18:26         ` Mark A. Greer
2012-07-19 18:26           ` Mark A. Greer
2012-07-19 19:19           ` Paul Walmsley
2012-07-19 19:19             ` Paul Walmsley
2012-07-19 20:20             ` Mark A. Greer
2012-07-19 20:20               ` Mark A. Greer
2012-07-19 22:59           ` Paul Walmsley
2012-07-19 22:59             ` Paul Walmsley
2012-07-20 21:41             ` Mark A. Greer
2012-07-20 21:41               ` Mark A. Greer
2012-05-11 21:18 ` Mark A. Greer [this message]
2012-05-14 23:28 ` [PATCH 0/2] arm: omap3: am35x: Convert emac to hwmod & disable hlt when open Kevin Hilman
2012-05-14 23:28   ` Kevin Hilman
2012-05-15 12:20   ` Sekhar Nori
2012-05-15 12:20     ` Sekhar Nori

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=20120511211845.GA10670@animalcreek.com \
    --to=mgreer@animalcreek.com \
    --cc=davinci-linux-open-source@linux.davincidsp.com \
    --cc=khilman@ti.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=paul@pwsan.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.