From patchwork Mon Feb 3 23:33:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 316384 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 238C32C0097 for ; Tue, 4 Feb 2014 10:33:53 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754381AbaBCXdr (ORCPT ); Mon, 3 Feb 2014 18:33:47 -0500 Received: from mail-la0-f54.google.com ([209.85.215.54]:43394 "EHLO mail-la0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754362AbaBCXdp (ORCPT ); Mon, 3 Feb 2014 18:33:45 -0500 Received: by mail-la0-f54.google.com with SMTP id y1so6022109lam.13 for ; Mon, 03 Feb 2014 15:33:44 -0800 (PST) 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=MtAEpxgsGTj9tMpT1X5f0gLutWfXq5U+uWlT8nhNd/A=; b=NKvNvxBvwdJo2hlrhYgc4Tv442wiNB3u8p6amiue9di1xW37abLUp9r6C+DCRsuocY 106PLzbwCCcMGt+3sd0s9n9p9fwlOcLg8LNfYNupVZVgRtVzChiJ7bu9FLrT85mbag1E +axRCsNW36Qvi5hSDxuSB6pnhhORMrzu4TalMpA32/vutysR+ag+f3CC1opI8GIVZnr4 6FgSq+lfCDcHxPOd3F+rZdL9Ky+8dAYQSDQVxP6IsbRN357IzuzhhZnv20PYvUNcljI0 xthmp1I2+VIVbj63hkCk5n8Ur0Ff1vh6x0jEiJWvSPw6WNfeJY71WrXJfnh/+Snp+G4A D6Mg== X-Received: by 10.152.203.193 with SMTP id ks1mr27312529lac.0.1391470423940; Mon, 03 Feb 2014 15:33:43 -0800 (PST) Received: from octofox.metropolis ([188.134.19.124]) by mx.google.com with ESMTPSA id mo3sm23040674lbb.17.2014.02.03.15.33.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Feb 2014 15:33:42 -0800 (PST) From: Max Filippov To: linux-xtensa@linux-xtensa.org, netdev@vger.kernel.org Cc: Chris Zankel , Marc Gauthier , "David S. Miller" , Ben Hutchings , Florian Fainelli , Max Filippov Subject: [PATCH v3 2/2] net: ethoc: set up MII management bus clock Date: Tue, 4 Feb 2014 03:33:10 +0400 Message-Id: <1391470390-31569-3-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1391470390-31569-1-git-send-email-jcmvbkbc@gmail.com> References: <1391470390-31569-1-git-send-email-jcmvbkbc@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org MII management bus clock is derived from the MAC clock by dividing it by MIIMODER register CLKDIV field value. This value may need to be set up in case it is undefined or its default value is too high (and communication with PHY is too slow) or too low (and communication with PHY is impossible). The value of CLKDIV is not specified directly, but is derived from the MAC clock for the default MII management bus frequency of 2.5MHz. The MAC clock may be specified in the platform data, or in the 'clocks' device tree attribute. Signed-off-by: Max Filippov --- Changes v2->v3: - drop clock-frequency property support. Changes v1->v2: - drop MDIO bus frequency configurability, always configure for standard 2.5MHz; - allow using common clock framework to provide ethoc clock. drivers/net/ethernet/ethoc.c | 32 ++++++++++++++++++++++++++++++-- include/net/ethoc.h | 1 + 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/ethoc.c b/drivers/net/ethernet/ethoc.c index 6aef639..41ca15d 100644 --- a/drivers/net/ethernet/ethoc.c +++ b/drivers/net/ethernet/ethoc.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -219,6 +220,7 @@ struct ethoc { struct phy_device *phy; struct mii_bus *mdio; + struct clk *clk; s8 phy_id; }; @@ -1021,6 +1023,8 @@ static int ethoc_probe(struct platform_device *pdev) int num_bd; int ret = 0; bool random_mac = false; + struct ethoc_platform_data *pdata = dev_get_platdata(&pdev->dev); + u32 eth_clkfreq = pdata ? pdata->eth_clkfreq : 0; /* allocate networking device */ netdev = alloc_etherdev(sizeof(struct ethoc)); @@ -1135,8 +1139,7 @@ static int ethoc_probe(struct platform_device *pdev) } /* Allow the platform setup code to pass in a MAC address. */ - if (dev_get_platdata(&pdev->dev)) { - struct ethoc_platform_data *pdata = dev_get_platdata(&pdev->dev); + if (pdata) { memcpy(netdev->dev_addr, pdata->hwaddr, IFHWADDRLEN); priv->phy_id = pdata->phy_id; } else { @@ -1174,6 +1177,27 @@ static int ethoc_probe(struct platform_device *pdev) if (random_mac) netdev->addr_assign_type = NET_ADDR_RANDOM; + /* Allow the platform setup code to adjust MII management bus clock. */ + if (!eth_clkfreq) { + struct clk *clk = devm_clk_get(&pdev->dev, NULL); + + if (!IS_ERR(clk)) { + priv->clk = clk; + clk_prepare_enable(clk); + eth_clkfreq = clk_get_rate(clk); + } + } + if (eth_clkfreq) { + u32 clkdiv = MIIMODER_CLKDIV(eth_clkfreq / 2500000 + 1); + + if (!clkdiv) + clkdiv = 2; + dev_dbg(&pdev->dev, "setting MII clkdiv to %u\n", clkdiv); + ethoc_write(priv, MIIMODER, + (ethoc_read(priv, MIIMODER) & MIIMODER_NOPRE) | + clkdiv); + } + /* register MII bus */ priv->mdio = mdiobus_alloc(); if (!priv->mdio) { @@ -1239,6 +1263,8 @@ free_mdio: kfree(priv->mdio->irq); mdiobus_free(priv->mdio); free: + if (priv->clk) + clk_disable_unprepare(priv->clk); free_netdev(netdev); out: return ret; @@ -1263,6 +1289,8 @@ static int ethoc_remove(struct platform_device *pdev) kfree(priv->mdio->irq); mdiobus_free(priv->mdio); } + if (priv->clk) + clk_disable_unprepare(priv->clk); unregister_netdev(netdev); free_netdev(netdev); } diff --git a/include/net/ethoc.h b/include/net/ethoc.h index 96f3789..2a2d6bb 100644 --- a/include/net/ethoc.h +++ b/include/net/ethoc.h @@ -16,6 +16,7 @@ struct ethoc_platform_data { u8 hwaddr[IFHWADDRLEN]; s8 phy_id; + u32 eth_clkfreq; }; #endif /* !LINUX_NET_ETHOC_H */