From patchwork Fri Sep 9 12:45:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Labbe X-Patchwork-Id: 9323313 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D7E7E60752 for ; Fri, 9 Sep 2016 12:51:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C992929E79 for ; Fri, 9 Sep 2016 12:51:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDB8429E7B; Fri, 9 Sep 2016 12:51:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5A17129E79 for ; Fri, 9 Sep 2016 12:51:39 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1biLFv-0007cc-5W; Fri, 09 Sep 2016 12:50:07 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1biLDB-0005op-Vv for linux-arm-kernel@lists.infradead.org; Fri, 09 Sep 2016 12:47:21 +0000 Received: by mail-wm0-x243.google.com with SMTP id l65so2609981wmf.3 for ; Fri, 09 Sep 2016 05:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=L8868RO74frod+PYaHpM9HDiITT4FlzI/C40M3IOufs=; b=eWd3Ub8J9LjAEWyI0Ywp8eKvsiLGk0H6baZp6sMQTqxI7oq5HEp6askLQTTU3xypR0 Se1hLwnoK+30Tl1nSKq7kaOO59YEK7l2/V/qjW37X0I/dQhtxnYfjkSnhn8c2X6r576b 1PxEE7aRCVLGtpeYUO1PcoKnEcpFxhzTNdv3ZQdp5noJP0ozMQOfnQPKugPNMhGNcW/C TXJVuCzPHR3vBQyMDe/oPwUhta4MdThEL2gXgLtQs7R+VfqfLjNhrpt6pJUBzVI68FZo el+JEjO5qtV3moXJnrxFsFTrY6oHOnbYtYmoSLJXxtVQhk+N3X+Om9WCIPVGMyWTEr3r OXZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=L8868RO74frod+PYaHpM9HDiITT4FlzI/C40M3IOufs=; b=BsC9B3q8eTdU52yqz7X7yOmFE9e9u4pgcr7PlNCqikaW+PpdrmawHv/7QpUExoKN5/ 0mdaVoW2T6+iKBpEgbEt/DvPGlS7P/VwCceimPADb9/x+EzTayIQsSef4jBfmPBuGZpP 2ZnXlJb6x3QBEF9GIzevX1Q0z7//JgjhyfLPun5BeaIUxD4/oU4a+gD4e66in9VSOV1G +kI5HpDwbbem9hipAEjMyEXbkA/vJSFhN8F8N4HF1INeh9moeu5ZmbZS0LqPwJ7CkGGk CUqx/iDj5ElJSiS0LXSra/jMIeTiCJ6MPabRXOgM3dxl3sj9P+OEMRCF5BtYWpP4L96J b0SQ== X-Gm-Message-State: AE9vXwMwitZagtfnnutaV/6vNzfCalnchHwrftODHBy9Xflw6RyF6eCiYwgjBPboVR1aWQ== X-Received: by 10.28.22.6 with SMTP id 6mr2930811wmw.55.1473425217089; Fri, 09 Sep 2016 05:46:57 -0700 (PDT) Received: from Red.local (LFbn-1-7035-57.w90-116.abo.wanadoo.fr. [90.116.208.57]) by smtp.googlemail.com with ESMTPSA id b188sm3192572wmg.24.2016.09.09.05.46.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Sep 2016 05:46:56 -0700 (PDT) From: Corentin Labbe To: robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@free-electrons.com, wens@csie.org, linux@armlinux.org.uk, davem@davemloft.net Subject: [RFC PATCH 9/9] ethernet: sun8i-emac: add pm_runtime support Date: Fri, 9 Sep 2016 14:45:17 +0200 Message-Id: <1473425117-18645-10-git-send-email-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1473425117-18645-1-git-send-email-clabbe.montjoie@gmail.com> References: <1473425117-18645-1-git-send-email-clabbe.montjoie@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160909_054718_779971_19FDEF46 X-CRM114-Status: GOOD ( 15.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: netdev@vger.kernel.org, Corentin Labbe , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add pm_runtime support to sun8i-emac. For the moment, only basic support is added, (the device is marked as used when net/open) Signed-off-by: Corentin Labbe --- drivers/net/ethernet/allwinner/sun8i-emac.c | 62 ++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/allwinner/sun8i-emac.c b/drivers/net/ethernet/allwinner/sun8i-emac.c index 1c4bc80..cce886e 100644 --- a/drivers/net/ethernet/allwinner/sun8i-emac.c +++ b/drivers/net/ethernet/allwinner/sun8i-emac.c @@ -9,7 +9,6 @@ * - MAC filtering * - Jumbo frame * - features rx-all (NETIF_F_RXALL_BIT) - * - PM runtime */ #include #include @@ -27,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -1301,11 +1301,18 @@ static int sun8i_emac_open(struct net_device *ndev) int err; u32 v; + err = pm_runtime_get_sync(priv->dev); + if (err) { + pm_runtime_put_noidle(priv->dev); + dev_err(priv->dev, "pm_runtime error: %d\n", err); + return err; + } + err = request_irq(priv->irq, sun8i_emac_dma_interrupt, 0, dev_name(priv->dev), ndev); if (err) { dev_err(priv->dev, "Cannot request IRQ: %d\n", err); - return err; + goto err_runtime; } /* Set interface mode (and configure internal PHY on H3) */ @@ -1395,6 +1402,8 @@ err_syscon: sun8i_emac_unset_syscon(ndev); err_irq: free_irq(priv->irq, ndev); +err_runtime: + pm_runtime_put(priv->dev); return err; } @@ -1483,6 +1492,8 @@ static int sun8i_emac_stop(struct net_device *ndev) dma_free_coherent(priv->dev, priv->nbdesc_tx * sizeof(struct dma_desc), priv->dd_tx, priv->dd_tx_phy); + pm_runtime_put(priv->dev); + return 0; } @@ -2210,6 +2221,8 @@ static int sun8i_emac_probe(struct platform_device *pdev) goto probe_err; } + pm_runtime_enable(priv->dev); + return 0; probe_err: @@ -2221,6 +2234,8 @@ static int sun8i_emac_remove(struct platform_device *pdev) { struct net_device *ndev = platform_get_drvdata(pdev); + pm_runtime_disable(&pdev->dev); + unregister_netdev(ndev); platform_set_drvdata(pdev, NULL); free_netdev(ndev); @@ -2228,6 +2243,47 @@ static int sun8i_emac_remove(struct platform_device *pdev) return 0; } +static int __maybe_unused sun8i_emac_suspend(struct platform_device *pdev, pm_message_t state) +{ + struct net_device *ndev = platform_get_drvdata(pdev); + struct sun8i_emac_priv *priv = netdev_priv(ndev); + + napi_disable(&priv->napi); + + if (netif_running(ndev)) + netif_device_detach(ndev); + + sun8i_emac_stop_tx(ndev); + sun8i_emac_stop_rx(ndev); + + sun8i_emac_rx_clean(ndev); + sun8i_emac_tx_clean(ndev); + + phy_stop(ndev->phydev); + + return 0; +} + +static int __maybe_unused sun8i_emac_resume(struct platform_device *pdev) +{ + struct net_device *ndev = platform_get_drvdata(pdev); + struct sun8i_emac_priv *priv = netdev_priv(ndev); + + phy_start(ndev->phydev); + + sun8i_emac_start_tx(ndev); + sun8i_emac_start_rx(ndev); + + if (netif_running(ndev)) + netif_device_attach(ndev); + + netif_start_queue(ndev); + + napi_enable(&priv->napi); + + return 0; +} + static const struct of_device_id sun8i_emac_of_match_table[] = { { .compatible = "allwinner,sun8i-a83t-emac", .data = &emac_variant_a83t }, @@ -2246,6 +2302,8 @@ static struct platform_driver sun8i_emac_driver = { .name = "sun8i-emac", .of_match_table = sun8i_emac_of_match_table, }, + .suspend = sun8i_emac_suspend, + .resume = sun8i_emac_resume, }; module_platform_driver(sun8i_emac_driver);