From patchwork Tue Aug 30 10:52:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 9305183 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 59F3260756 for ; Tue, 30 Aug 2016 10:55:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A21C28A9D for ; Tue, 30 Aug 2016 10:55:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F3C328AB3; Tue, 30 Aug 2016 10:55:25 +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_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham 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 DF46328A9D for ; Tue, 30 Aug 2016 10:55:24 +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 1begfz-0008L8-WA; Tue, 30 Aug 2016 10:53:56 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:1be6]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1begfB-0007eZ-16 for linux-arm-kernel@lists.infradead.org; Tue, 30 Aug 2016 10:53:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Date:Sender:Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References:In-Reply-To; bh=zunJYeDjn1XFb/DOtxUqD3FiJCgLckXZ0bOWWS5ZFk0=; b=SKAu+rBStgj1oMUfsFwjo03QQD8JnWNcU/i0Zx58sneavzRqmoA///ega/tqDtM1lsfQU7HKcTssajAySNU/AKbV+LDZmn0NlV6DFMaxzEEx9HcYrpwfVc0OobmBwL6SbPN8DjZ/Voa8Z99wtN2W/+zqUkkVvBQ6MidglNMI0cQ=; Received: from e0022681537dd.dyn.armlinux.org.uk ([2001:4d48:ad52:3201:222:68ff:fe15:37dd]:56380 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1begen-0004Uk-97; Tue, 30 Aug 2016 11:52:41 +0100 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1begem-00076w-Ef; Tue, 30 Aug 2016 11:52:40 +0100 In-Reply-To: <20160830105117.GM1041@n2100.armlinux.org.uk> References: <20160830105117.GM1041@n2100.armlinux.org.uk> From: Russell King To: linux-arm-kernel@lists.infradead.org,netdev@vger.kernel.org Subject: [PATCH 2/4] net: smc91x: add external clock support MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Tue, 30 Aug 2016 11:52:40 +0100 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160830_035305_618213_B92BD450 X-CRM114-Status: GOOD ( 16.73 ) 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: Nicolas Pitre 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 The smc91x can be operated with either a directly attached crystal, or an externally supplied clock. When used with an externally supplied clock, this clock may require some configuration or control. Add calls to the driver to lookup, enable and disable this optional clock. Signed-off-by: Russell King --- drivers/net/ethernet/smsc/smc91x.c | 38 ++++++++++++++++++++++++++++++++++++-- drivers/net/ethernet/smsc/smc91x.h | 1 + 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/smsc/smc91x.c b/drivers/net/ethernet/smsc/smc91x.c index 503a3b6dce91..43dbc1c7b9a5 100644 --- a/drivers/net/ethernet/smsc/smc91x.c +++ b/drivers/net/ethernet/smsc/smc91x.c @@ -73,6 +73,7 @@ static const char version[] = #include #include #include +#include #include #include #include @@ -2284,6 +2285,18 @@ static int smc_drv_probe(struct platform_device *pdev) } } + /* + * Some platforms drive the xtal input from an external clock + * source which may require some control. Request the clock, + * but allow probing to continue if no clock is specified. + */ + lp->xtal = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(lp->xtal)) { + if (PTR_ERR(lp->xtal) != -ENOENT) + return PTR_ERR(lp->xtal); + lp->xtal = NULL; + } + #if IS_BUILTIN(CONFIG_OF) match = of_match_device(of_match_ptr(smc91x_match), &pdev->dev); if (match) { @@ -2375,15 +2388,20 @@ static int smc_drv_probe(struct platform_device *pdev) if (machine_is_assabet() && machine_has_neponset()) neponset_ncr_set(NCR_ENET_OSC_EN); #endif + if (lp->xtal) { + ret = clk_prepare_enable(lp->xtal); + if (ret) + goto out_release_attrib; + } platform_set_drvdata(pdev, ndev); ret = smc_enable_device(pdev); if (ret) - goto out_release_attrib; + goto out_disable_xtal; addr = ioremap(res->start, SMC_IO_EXTENT); if (!addr) { ret = -ENOMEM; - goto out_release_attrib; + goto out_disable_xtal; } #ifdef CONFIG_ARCH_PXA @@ -2407,6 +2425,9 @@ static int smc_drv_probe(struct platform_device *pdev) iounmap(addr); out_release_attrib: smc_release_attrib(pdev, ndev); + out_disable_xtal: + if (lp->xtal) + clk_disable_unprepare(lp->xtal); out_release_io: release_mem_region(res->start, SMC_IO_EXTENT); out_free_netdev: @@ -2441,6 +2462,9 @@ static int smc_drv_remove(struct platform_device *pdev) res = platform_get_resource(pdev, IORESOURCE_MEM, 0); release_mem_region(res->start, SMC_IO_EXTENT); + if (lp->xtal) + clk_disable_unprepare(lp->xtal); + free_netdev(ndev); return 0; @@ -2453,9 +2477,14 @@ static int smc_drv_suspend(struct device *dev) if (ndev) { if (netif_running(ndev)) { + struct smc_local *lp = netdev_priv(ndev); + netif_device_detach(ndev); smc_shutdown(ndev); smc_phy_powerdown(ndev); + + if (lp->xtal) + clk_disable_unprepare(lp->xtal); } } return 0; @@ -2468,6 +2497,11 @@ static int smc_drv_resume(struct device *dev) if (ndev) { struct smc_local *lp = netdev_priv(ndev); + if (lp->xtal) { + int ret = clk_prepare_enable(lp->xtal); + if (ret) + return ret; + } smc_enable_device(pdev); if (netif_running(ndev)) { smc_reset(ndev); diff --git a/drivers/net/ethernet/smsc/smc91x.h b/drivers/net/ethernet/smsc/smc91x.h index e17671c9d1b0..5377c2e1b8b9 100644 --- a/drivers/net/ethernet/smsc/smc91x.h +++ b/drivers/net/ethernet/smsc/smc91x.h @@ -266,6 +266,7 @@ struct smc_local { struct gpio_desc *power_gpio; struct gpio_desc *reset_gpio; + struct clk *xtal; /* version/revision of the SMC91x chip */ int version;