From patchwork Thu Oct 12 03:32:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 115577 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp1462914qgn; Wed, 11 Oct 2017 20:32:46 -0700 (PDT) X-Received: by 10.101.87.202 with SMTP id q10mr968892pgr.141.1507779166020; Wed, 11 Oct 2017 20:32:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507779166; cv=none; d=google.com; s=arc-20160816; b=kN54OpB9PBiW8A0w/6pX7fy/bN9yaQN+WRtAihvEhh/gzn+hj9wLmHFvGINxAOzZPh 6NbFc0QeWzt07JaW2e+ZzGoDyIizFhXs0cj4wXBxEtDj7jS/aL5dHnWOnC0gKJUzKodG knUW3nd3M+UHxz8GlAWDaVZb0fOYKfIn+7SC54DiAXb/q617BB4ji/0MVHEBF3vVNDiV XvJ83fWwVIxS8rGtHqv3PNHs/GsCUvXOv81Ns9eYUONpvrzlDrPgSI/YxFnZSbBG45H8 AXZ/78qzPxQemYAYawUVlLZp55GjAiiM5thMLSFEUj+jO1XW1C2OH7INVCMEUXXp+jyo /ojQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Jsz9aAkjMl1m7BOzxtFC+yJdZCM2TghXuDjzUOP0J7k=; b=j74tKBcymtbO9Zk5XR+DhWkUqI92LJmS8mGrbCL7nXz+DqgK2JwuJ7NY1auFEUIGZH mX34/WuRwHYul44iALEsVsJuMNNoCWuQ1U/DLMSpWQOKK8vrk371C4QoRQP7Ve7p/I/4 7tQJ8QUIkjx3nNO/qr7EnGEx3p+R+82nFvW1z5JwZ5HgR1XqfD5EL4oDW/AWMl9jLwYl 3Pb0XaGM2UvwIEtwV8lETXdgfh8DyUKMthfu5kZt4ugTq502cbMhX3o8u+pPobiCh9ZC 3UJ/nTcqGjvJEHk3sAdIRERgDOF/nE+PE9ghUOQ55BSIIrkLJ20z6xdQHMdtHsXGcC4a CwZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@jms.id.au header.s=google header.b=ie2rRlxs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 68si11695440pla.106.2017.10.11.20.32.45; Wed, 11 Oct 2017 20:32:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@jms.id.au header.s=google header.b=ie2rRlxs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752982AbdJLDcl (ORCPT + 27 others); Wed, 11 Oct 2017 23:32:41 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:37300 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751347AbdJLDcj (ORCPT ); Wed, 11 Oct 2017 23:32:39 -0400 Received: by mail-pf0-f196.google.com with SMTP id z80so4234525pff.4 for ; Wed, 11 Oct 2017 20:32:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jms.id.au; s=google; h=from:to:cc:subject:date:message-id; bh=Jsz9aAkjMl1m7BOzxtFC+yJdZCM2TghXuDjzUOP0J7k=; b=ie2rRlxsyvQZjt2LvvnBVZunbUuvpMb3HliRll6zxV4PplrPGbvxPLboa//QnhjD16 VY5nj64SDSf3NeY/5ySMFOSt6UQkGiacgF4ZOnyYqNxFimdZ/TAp1YTgJIGGJ4ZDkKzD n+BE/mzNcBTnH+fWm8Blu+5ebW4kPF2mjFabM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Jsz9aAkjMl1m7BOzxtFC+yJdZCM2TghXuDjzUOP0J7k=; b=E3Zf8hPHu4Yvz0h/oOxHgqiyW/jZmDSsEjUpz3/uy5YVdAWfDUycOxRxGgU+Ebc15r SE1ClLhxis2W7vO7dZpCmrBycj2aYJWbGKRrpreMBuneJOhQn65zvoHhbPP6tqE8FxDw VWL9unCqPoALyX5CzrdYYOLh6v2jCTtz29j+Utjli1eAJKz8omHBgGRj+ZlUzrSbWQ2y Mygqqh3Jtq2WVtqx+hyIKR07/ndEX6gK2pfFbiXdm6OogLF5SfEn+qjqXW17hE4j9xtV aSjgccCgpvvcgTJnjaXsN3A0H8vNmIK2+OV4r3HpLoL+87mheN4sSo1cush6u1S76kj2 E7mQ== X-Gm-Message-State: AMCzsaWRbQRWBtLljxLQ7I1thvHFoZLpqGLlyMHZSOT8XWxhVMwcWlCH EURibi4ByBBHSrWsi6VRWs+JtSlCzvei6A== X-Google-Smtp-Source: AOwi7QAs8LPFHa67jLmSACKKoVgy4Pzd0N9oZrOAzXnPjeK6GI+Ksrt3/v0ePEmN7tsPFX+EaBc1dA== X-Received: by 10.159.194.196 with SMTP id u4mr969807plz.49.1507779158926; Wed, 11 Oct 2017 20:32:38 -0700 (PDT) Received: from E402SA.smb.com ([122.116.41.53]) by smtp.gmail.com with ESMTPSA id d124sm25321840pfc.42.2017.10.11.20.32.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Oct 2017 20:32:38 -0700 (PDT) From: Joel Stanley To: "David S . Miller" , Benjamin Herrenschmidt Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Jeffery Subject: [PATCH v2] net: ftgmac100: Request clock and set speed Date: Thu, 12 Oct 2017 11:32:01 +0800 Message-Id: <20171012033201.12845-1-joel@jms.id.au> X-Mailer: git-send-email 2.14.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org According to the ASPEED datasheet, gigabit speeds require a clock of 100MHz or higher. Other speeds require 25MHz or higher. This patch configures a 100MHz clock if the system has a direct-attached PHY, or 25MHz if the system is running NC-SI which is limited to 100MHz. There appear to be no other upstream users of the FTGMAC100 driver so it is hard to know the clocking requirements of other platforms. Therefore a conservative approach was taken with enabling clocks. If the platform is not ASPEED, both requesting the clock and configuring the speed is skipped. Signed-off-by: Joel Stanley --- Andrew, as I'm travelling can you please test this on the evb and a palmetto? Use my wip/aspeed-v4.14-clk branch, or OpenBMC's dev-4.13. David, please wait for Andrew's tested-by before applying. Cheers! v2: - only touch the clocks on Aspeed platforms - unconditionally call clk_unprepare_disable drivers/net/ethernet/faraday/ftgmac100.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) -- 2.14.1 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c index 9ed8e4b81530..cd352bf41da1 100644 --- a/drivers/net/ethernet/faraday/ftgmac100.c +++ b/drivers/net/ethernet/faraday/ftgmac100.c @@ -21,6 +21,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -59,6 +60,9 @@ /* Min number of tx ring entries before stopping queue */ #define TX_THRESHOLD (MAX_SKB_FRAGS + 1) +#define FTGMAC_100MHZ 100000000 +#define FTGMAC_25MHZ 25000000 + struct ftgmac100 { /* Registers */ struct resource *res; @@ -96,6 +100,7 @@ struct ftgmac100 { struct napi_struct napi; struct work_struct reset_task; struct mii_bus *mii_bus; + struct clk *clk; /* Link management */ int cur_speed; @@ -1734,6 +1739,22 @@ static void ftgmac100_ncsi_handler(struct ncsi_dev *nd) nd->link_up ? "up" : "down"); } +static void ftgmac100_setup_clk(struct ftgmac100_priv *priv) +{ + priv->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(priv->clk)) + return; + + clk_prepare_enable(priv->clk); + + /* Aspeed specifies a 100MHz clock is required for up to + * 1000Mbit link speeds. As NCSI is limited to 100Mbit, 25MHz + * is sufficient + */ + clk_set_rate(priv->clk, priv->is_ncsi ? FTGMAC_25MHZ : + FTGMAC_100MHZ); +} + static int ftgmac100_probe(struct platform_device *pdev) { struct resource *res; @@ -1830,6 +1851,9 @@ static int ftgmac100_probe(struct platform_device *pdev) goto err_setup_mdio; } + if (priv->is_aspeed) + ftgmac100_setup_clk(priv); + /* Default ring sizes */ priv->rx_q_entries = priv->new_rx_q_entries = DEF_RX_QUEUE_ENTRIES; priv->tx_q_entries = priv->new_tx_q_entries = DEF_TX_QUEUE_ENTRIES; @@ -1883,6 +1907,8 @@ static int ftgmac100_remove(struct platform_device *pdev) unregister_netdev(netdev); + clk_disable_unprepare(priv->clk); + /* There's a small chance the reset task will have been re-queued, * during stop, make sure it's gone before we free the structure. */