From patchwork Fri Jul 17 12:59:05 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfgang Denk X-Patchwork-Id: 29921 Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 41190B70E5 for ; Fri, 17 Jul 2009 22:59:47 +1000 (EST) Received: by ozlabs.org (Postfix) id 34AAFDDD0C; Fri, 17 Jul 2009 22:59:47 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from bilbo.ozlabs.org (bilbo.ozlabs.org [203.10.76.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "bilbo.ozlabs.org", Issuer "CAcert Class 3 Root" (verified OK)) by ozlabs.org (Postfix) with ESMTPS id 32F6CDDD0B for ; Fri, 17 Jul 2009 22:59:47 +1000 (EST) Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by bilbo.ozlabs.org (Postfix) with ESMTP id DE6C6B7DDC for ; Fri, 17 Jul 2009 22:59:18 +1000 (EST) Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 6A4E7B7099 for ; Fri, 17 Jul 2009 22:59:11 +1000 (EST) Received: by ozlabs.org (Postfix) id 59C57DDD0C; Fri, 17 Jul 2009 22:59:11 +1000 (EST) Delivered-To: linuxppc-dev@ozlabs.org Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.10]) by ozlabs.org (Postfix) with ESMTP id A67E7DDD04 for ; Fri, 17 Jul 2009 22:59:09 +1000 (EST) Received: from mail01.m-online.net (mail.m-online.net [192.168.3.149]) by mail-out.m-online.net (Postfix) with ESMTP id C93FA1C001D0; Fri, 17 Jul 2009 14:59:07 +0200 (CEST) Received: from localhost (dynscan2.mnet-online.de [192.168.1.215]) by mail.m-online.net (Postfix) with ESMTP id BADD7902D1; Fri, 17 Jul 2009 14:59:07 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from smtp-auth.mnet-online.de ([192.168.3.149]) by localhost (dynscan2.mnet-online.de [192.168.1.215]) (amavisd-new, port 10024) with ESMTP id S3B2k8MR+d48; Fri, 17 Jul 2009 14:59:06 +0200 (CEST) X-Auth-Info: P/OX9E55RiIqPVEkUSpAuXs9keFApFFJ22/ro2lzFZw= Received: from diddl.denx.de (ppp-88-217-54-40.dynamic.mnet-online.de [88.217.54.40]) by smtp-auth.mnet-online.de (Postfix) with ESMTP; Fri, 17 Jul 2009 14:59:06 +0200 (CEST) Received: from gemini.denx.de (unknown [10.0.0.2]) by diddl.denx.de (Postfix) with ESMTP id 10159C913180; Fri, 17 Jul 2009 14:59:06 +0200 (CEST) Received: by gemini.denx.de (Postfix, from userid 500) id 01A08832E416; Fri, 17 Jul 2009 14:59:06 +0200 (CEST) From: Wolfgang Denk To: linuxppc-dev@ozlabs.org Subject: [PATCH 2/2 v4] MPC52xx FEC: be more conservative when setting MII_SPEED register Date: Fri, 17 Jul 2009 14:59:05 +0200 Message-Id: <1247835545-18650-1-git-send-email-wd@denx.de> X-Mailer: git-send-email 1.6.0.6 In-Reply-To: <1247833628-15952-2-git-send-email-wd@denx.de> References: <1247833628-15952-2-git-send-email-wd@denx.de> Cc: netdev@vger.kernel.org, Wolfgang Denk X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org This patch adds error checking and prevents clobbering unrelated bits (reserved bits or the DIS_PREAMBLE bit) when writing the MII_SPEED register on MPC52xx systems. Signed-off-by: Wolfgang Denk Cc: Grant Likely Cc: Kumar Gala Cc: --- v3: - use maximum divider in case MPC512x IPS clock is unknown v4: - use the same code in the probe-function, too drivers/net/fec_mpc52xx.c | 25 ++++++++++++++++++++++--- drivers/net/fec_mpc52xx_phy.c | 23 ++++++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/drivers/net/fec_mpc52xx.c b/drivers/net/fec_mpc52xx.c index cc78633..eed8d2b 100644 --- a/drivers/net/fec_mpc52xx.c +++ b/drivers/net/fec_mpc52xx.c @@ -639,7 +639,7 @@ static void mpc52xx_fec_hw_init(struct net_device *dev) /* set phy speed. * this can't be done in phy driver, since it needs to be called * before fec stuff (even on resume) */ - out_be32(&fec->mii_speed, priv->mdio_speed); + clrsetbits_be32(&fec->mii_speed, 0x7E, priv->mdio_speed); } /** @@ -863,7 +863,7 @@ mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match) struct mpc52xx_fec_priv *priv = NULL; struct resource mem; const u32 *prop; - int prop_size; + int prop_size, clock, speed; phys_addr_t rx_fifo; phys_addr_t tx_fifo; @@ -948,7 +948,26 @@ mpc52xx_fec_probe(struct of_device *op, const struct of_device_id *match) /* Start with safe defaults for link connection */ priv->speed = 100; priv->duplex = DUPLEX_HALF; - priv->mdio_speed = ((mpc5xxx_get_bus_frequency(op->node) >> 20) / 5) << 1; + + /* MII speed */ + clock = mpc5xxx_get_bus_frequency(op->node); + if (!clock) { + /* Use maximum divider if clock is unknown */ + dev_err(&op->dev, "could not determine IPB clock\n"); + clock = 0x3F * 5000000; + } + + /* + * Scale for a MII clock <= 2.5 MHz + * Note that only 6 bits (25:30) are available for MII speed. + */ + speed = (clock + 4999999) / 5000000; + if (speed > 0x3F) { + speed = 0x3F; + dev_err(&op->dev, "MII clock (%d Hz) exceeds max (2.5 MHz)\n", + clock / speed); + } + priv->mdio_speed = speed << 1; /* The current speed preconfigures the speed of the MII link */ prop = of_get_property(op->node, "current-speed", &prop_size); diff --git a/drivers/net/fec_mpc52xx_phy.c b/drivers/net/fec_mpc52xx_phy.c index 31e6d62..d3537e1 100644 --- a/drivers/net/fec_mpc52xx_phy.c +++ b/drivers/net/fec_mpc52xx_phy.c @@ -70,7 +70,7 @@ static int mpc52xx_fec_mdio_probe(struct of_device *of, struct mpc52xx_fec_mdio_priv *priv; struct resource res = {}; int err; - int i; + int i, clock, speed; bus = mdiobus_alloc(); if (bus == NULL) @@ -105,8 +105,25 @@ static int mpc52xx_fec_mdio_probe(struct of_device *of, dev_set_drvdata(dev, bus); /* set MII speed */ - out_be32(&priv->regs->mii_speed, - ((mpc5xxx_get_bus_frequency(of->node) >> 20) / 5) << 1); + clock = mpc5xxx_get_bus_frequency(of->node); + if (!clock) { + /* Use maximum divider if clock is unknown */ + dev_err(&of->dev, "could not determine IPB clock\n"); + clock = 0x3F * 5000000; + } + + /* + * Scale for a MII clock <= 2.5 MHz + * Note that only 6 bits (25:30) are available for MII speed. + */ + speed = (clock + 4999999) / 5000000; + if (speed > 0x3F) { + speed = 0x3F; + dev_err(&of->dev, "MII clock (%d Hz) exceeds max (2.5 MHz)\n", + clock / speed); + } + + clrsetbits_be32(&priv->regs->mii_speed, 0x7E, speed << 1); err = of_mdiobus_register(bus, np); if (err)