From patchwork Mon Jan 27 03:59:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 314300 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 E39B62C0089 for ; Mon, 27 Jan 2014 15:00:16 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753487AbaA0D7w (ORCPT ); Sun, 26 Jan 2014 22:59:52 -0500 Received: from mail-lb0-f174.google.com ([209.85.217.174]:50337 "EHLO mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753203AbaA0D7u (ORCPT ); Sun, 26 Jan 2014 22:59:50 -0500 Received: by mail-lb0-f174.google.com with SMTP id l4so4002636lbv.5 for ; Sun, 26 Jan 2014 19:59:48 -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=IIuh94ENvTRkk/oGCv9VYdo91l0M/XX+ySHEFykB9rc=; b=WVZYmx+qzQ527AwbFjB0Id+GgTXlEZBTHjEL3X8rxPCud11UjJJm8/NXH8X3BCaZCM 1XsBSfBdnvLU05hx3KlyxAZKX0qAaZwoS9HukkQ0MoOlQhoQzBO8QXzKmcOX0qlOOI6x bekEpUiRhc0mY0xDahKJ81Ioh6uUcE8HRVsQYH2EbosCOOTnw5Co5Y5qXb7YRz22d6j6 RIi+FPj+o+LHZuObVgZiiAWAnSvSgKvsi3FhoS90I90hpDylAlwrSHEdqbBEdQauke6h 9vb6iLuovHJiw1zYK7bUKE+ONst98z4jFJT5eUHoE1qQjhjBhyni94aljW5S5sfzPPUl sPeQ== X-Received: by 10.152.120.37 with SMTP id kz5mr3166295lab.30.1390795188227; Sun, 26 Jan 2014 19:59:48 -0800 (PST) Received: from octofox.metropolis ([188.134.19.124]) by mx.google.com with ESMTPSA id bn5sm10614129lbc.10.2014.01.26.19.59.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Jan 2014 19:59:47 -0800 (PST) From: Max Filippov To: linux-xtensa@linux-xtensa.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Chris Zankel , Marc Gauthier , "David S. Miller" , Grant Likely , Rob Herring , Max Filippov Subject: [PATCH 2/3] net: ethoc: set up MII management bus clock Date: Mon, 27 Jan 2014 07:59:26 +0400 Message-Id: <1390795167-6677-3-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1390795167-6677-1-git-send-email-jcmvbkbc@gmail.com> References: <1390795167-6677-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 as a pair of MAC frequency and desired MII management bus frequency, as these parameters are natural. Signed-off-by: Max Filippov --- drivers/net/ethernet/ethoc.c | 27 +++++++++++++++++++++++++-- include/net/ethoc.h | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/ethoc.c b/drivers/net/ethernet/ethoc.c index 0aa1a05..5831406 100644 --- a/drivers/net/ethernet/ethoc.c +++ b/drivers/net/ethernet/ethoc.c @@ -919,6 +919,9 @@ static int ethoc_probe(struct platform_device *pdev) int num_bd; int ret = 0; bool random_mac = false; + u32 eth_clkfreq = 0; + u32 mii_clkfreq = 0; + struct ethoc_platform_data *pdata = dev_get_platdata(&pdev->dev); /* allocate networking device */ netdev = alloc_etherdev(sizeof(struct ethoc)); @@ -1032,8 +1035,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 { @@ -1071,6 +1073,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 (pdata) { + eth_clkfreq = pdata->eth_clkfreq; + mii_clkfreq = pdata->mii_mgmt_clkfreq; + } else { + of_property_read_u32(pdev->dev.of_node, + "clock-frequency", ð_clkfreq); + of_property_read_u32(pdev->dev.of_node, + "mii-mgmt-clock-frequency", &mii_clkfreq); + } + if (eth_clkfreq && mii_clkfreq) { + u32 clkdiv = MIIMODER_CLKDIV(eth_clkfreq / mii_clkfreq + 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) { diff --git a/include/net/ethoc.h b/include/net/ethoc.h index 96f3789..b292474 100644 --- a/include/net/ethoc.h +++ b/include/net/ethoc.h @@ -16,6 +16,8 @@ struct ethoc_platform_data { u8 hwaddr[IFHWADDRLEN]; s8 phy_id; + u32 eth_clkfreq; + u32 mii_mgmt_clkfreq; }; #endif /* !LINUX_NET_ETHOC_H */