From patchwork Tue Oct 10 04:49:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 115333 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3322333qgn; Mon, 9 Oct 2017 21:49:47 -0700 (PDT) X-Received: by 10.84.234.198 with SMTP id i6mr4456531plt.410.1507610986864; Mon, 09 Oct 2017 21:49:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507610986; cv=none; d=google.com; s=arc-20160816; b=hoKPUDQpTReoItC6Y33GB+0ru/Jgb7Ccdj+rU7cUmQ0TQpW3Af5L1am2jleINroxjw ZhaLjz4ocrV4bKzsJBtplW/nbUhrs20mGOEAk/KUBrg+Cnvx/iBu7RpqVfc33nWRzheg l8Cz/NXv4/1tdvITbXqZ+PTQ3XQzR3n6Ldc4y0kohpCicU4dAx8LEi2V0vUGAZ4nUntt kaZB9jYsQFiSv97VzZlFHW984Rsge9cH6CDnnWx+mcTXaK353Fm/40pTCoxI4QZPl26h 7Ndg6Ou8evtQFVN5QXuPjj6IxZtsQnqQQjj6uKRITJRZUXBKKQJHKw+w7u/NNTBS/hGm MOaw== 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=1/0CEXecr4nUmlIFzHtyVxYcDv1i5ZsgfTff1wPJ6/A=; b=DbtQM5ERXeMOBTZ0ToIcrrl/B/ZkwctGM74erTgq1Oe+JG+oE18TEsLWLJocYQU5by Jlv5nbuq5zFjYcLds6oUZjs0sA1t4zJOH8ktvPFvmrAC6p8teEb1vO8YRuPa23YSLMFu 8tEc1wuGtRp4ftl1pcmPJaeQO4qs1LNasD/EfV9n/aCtBUdEbT84MbR/UBwLZTBwFllF BRHUouZPTm9q9viYT8mBXCeQLi9aPGjvHKG87NZWCKAV+grY77J5jvpL2OPYjlTODvn0 weCzrHTxFh0mqvdqDQdIpmEsaMKaFqNDxxThkWldEVoqCRxlBvCTL6yi/DNhezN+qlPX waPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=NuywmNu9; 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 y1si7470227pgp.587.2017.10.09.21.49.46; Mon, 09 Oct 2017 21:49: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=fail header.i=@gmail.com header.s=20161025 header.b=NuywmNu9; 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 S1752207AbdJJEto (ORCPT + 26 others); Tue, 10 Oct 2017 00:49:44 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33468 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751853AbdJJEtm (ORCPT ); Tue, 10 Oct 2017 00:49:42 -0400 Received: by mail-pf0-f195.google.com with SMTP id m28so32608294pfi.0; Mon, 09 Oct 2017 21:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=1/0CEXecr4nUmlIFzHtyVxYcDv1i5ZsgfTff1wPJ6/A=; b=NuywmNu9pUsL2FRW+QNPvDiQCCzfyFaf5wkqJsuHsofqmPZ++GNCQo13euUILvO4jQ A6/m1o+eREGYskFFkhKnNU6gOxG5qG9ApRsjmPf7OqZTXSRmyxFxMXXyEyUhmK4y3GjN IhZfVGaj1MXdfTPIgipzwsdvk54oApaOnjtf13qUxvy6dDO8XHgQgk98z0mnyq9S+JLD a/c5VSYz0+cvCsbdzK/DDz+9A77m7ZXOQLN0lE8BSMuwo8fSvAyWCsF+z+MeJ8r7lpfI 5iBcQY/CBeuVZAsgGz2LPIUV4gjZWYbZ5RGB5zQ0JVu946El9HFCzvT08tltHQFS/dHa lVrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=1/0CEXecr4nUmlIFzHtyVxYcDv1i5ZsgfTff1wPJ6/A=; b=MBtgo3d9kM2HaefgGn83M/9uT1CfM2khwBRNx3acfZke9ynkecoqUXZj2O8jxjJdyz DJA0yIxaAFpePUYiK+qqLXkFWAULUzv6VZc0bQLcz3vMLVebCMi1x++x+JLpCufRFcqv Jh/MFWGBSffpL4kRN+sLUbZ/LgY8Fh5ZWRlxrnsnZW9yAkqdf58IK28+FTFHNJ5/xNIO dWKrK02AHpK/NBEMizrmfNnEoTxucYXn94Yq03kXGMJHj8v+zzCm5u8gNBM6gbSFMgN6 AKBrT2As7odNuzNGVAf5c7TetqjZFB1M6ujt8bgeGMsNRcCAhLYdTQxTo+T5Pxm009Zi nt6g== X-Gm-Message-State: AMCzsaW/ZL8uprg9nJ2dtU9icenYEJe/OzUKTevQ+mFecba6JW5ybyGo pO4OKT/HTQwR+2hg0vpGa60= X-Google-Smtp-Source: AOwi7QB0xX2fHv82LDKOmkZ1PvkE1or8jUuFolq3OYi6AM8w68Q/m9lfS+qAQEXnUyx1ouZCiLj3xg== X-Received: by 10.98.10.74 with SMTP id s71mr12439380pfi.336.1507610982120; Mon, 09 Oct 2017 21:49:42 -0700 (PDT) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id e84sm11257023pfd.1.2017.10.09.21.49.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Oct 2017 21:49:40 -0700 (PDT) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Tue, 10 Oct 2017 15:19:33 +1030 From: Joel Stanley To: "David S . Miller" , Benjamin Herrenschmidt Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andrew Jeffery Subject: [PATCH] net: ftgmac100: Request clock and set speed Date: Tue, 10 Oct 2017 15:19:25 +1030 Message-Id: <20171010044925.21078-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. Signed-off-by: Joel Stanley --- drivers/net/ethernet/faraday/ftgmac100.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) -- 2.14.1 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c index 9ed8e4b81530..870ebd857978 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; @@ -142,18 +147,22 @@ static int ftgmac100_reset_mac(struct ftgmac100 *priv, u32 maccr) static int ftgmac100_reset_and_config_mac(struct ftgmac100 *priv) { u32 maccr = 0; + int freq = 0; switch (priv->cur_speed) { case SPEED_10: case 0: /* no link */ + freq = FTGMAC_25MHZ; break; case SPEED_100: maccr |= FTGMAC100_MACCR_FAST_MODE; + freq = FTGMAC_25MHZ; break; case SPEED_1000: maccr |= FTGMAC100_MACCR_GIGA_MODE; + freq = FTGMAC_100MHZ; break; default: netdev_err(priv->netdev, "Unknown speed %d !\n", @@ -161,6 +170,9 @@ static int ftgmac100_reset_and_config_mac(struct ftgmac100 *priv) break; } + if (freq && priv->clk) + clk_set_rate(priv->clk, freq); + /* (Re)initialize the queue pointers */ priv->rx_pointer = 0; priv->tx_clean_pointer = 0; @@ -1775,6 +1787,13 @@ static int ftgmac100_probe(struct platform_device *pdev) priv->dev = &pdev->dev; INIT_WORK(&priv->reset_task, ftgmac100_reset_task); + /* Enable clock if present */ + priv->clk = devm_clk_get(&pdev->dev, NULL); + if (!IS_ERR(priv->clk)) + clk_prepare_enable(priv->clk); + else + priv->clk = NULL; + /* map io memory */ priv->res = request_mem_region(res->start, resource_size(res), dev_name(&pdev->dev)); @@ -1883,6 +1902,9 @@ static int ftgmac100_remove(struct platform_device *pdev) unregister_netdev(netdev); + if (priv->clk) + 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. */