From patchwork Wed Aug 20 17:42:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 381801 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id BED09140093 for ; Thu, 21 Aug 2014 07:01:48 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 143C3A74A2; Wed, 20 Aug 2014 23:01:37 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ECYI7il-w06e; Wed, 20 Aug 2014 23:01:36 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C3CF9A74A8; Wed, 20 Aug 2014 23:00:39 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A8D0EA73E2 for ; Wed, 20 Aug 2014 19:49:09 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uuJ-7rlvxJ5X for ; Wed, 20 Aug 2014 19:49:06 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com [209.85.217.180]) by theia.denx.de (Postfix) with ESMTPS id 65FDBA73E5 for ; Wed, 20 Aug 2014 19:49:02 +0200 (CEST) Received: by mail-lb0-f180.google.com with SMTP id v6so7032983lbi.39 for ; Wed, 20 Aug 2014 10:49:02 -0700 (PDT) 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=wNbRNngbRo30hFc86ATI0pjSLsMdymnE4rtusZS6MRE=; b=WNkI2YKhWEbF7+TeY7NCdjwiGwnC6q5Ex6CGMXoLLz8OGmCwyYOatsel7M+5lLY92g D+hQqHu44DLIarreW5KQ4JnXgv3E37zR3Pb6B5WJlTOvL2ui1UcYmBGCT6ROq+fhpHPw 7+KcOFs7NXjRfenMpE1AVCLgfvPdoMb4D19cHnPiwDRUudnnpFd1V3OfYjs+GRRDyLM5 pEETSXsO87WaxGERPW/fsF9sDjKT7PBGKL7A/s/JI0bVB5hVp3xAc1ydLS1ForrJ+6FD WdG2JwvPZKQmJuQdlFP9BN6ZMBzA1tn04G0jm7JUwTXqz0+4KcG8oejYyHF1ALAf4fyD nQ0Q== X-Received: by 10.152.28.134 with SMTP id b6mr29796584lah.33.1408556561531; Wed, 20 Aug 2014 10:42:41 -0700 (PDT) Received: from octofox.metropolis ([5.18.160.9]) by mx.google.com with ESMTPSA id b6sm1182296laa.21.2014.08.20.10.42.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Aug 2014 10:42:40 -0700 (PDT) From: Max Filippov To: u-boot@lists.denx.de Date: Wed, 20 Aug 2014 21:42:08 +0400 Message-Id: <1408556533-22433-4-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1408556533-22433-1-git-send-email-jcmvbkbc@gmail.com> References: <1408556533-22433-1-git-send-email-jcmvbkbc@gmail.com> X-Mailman-Approved-At: Wed, 20 Aug 2014 23:00:32 +0200 Cc: Tom Rini , Marc Gauthier Subject: [U-Boot] [PATCH 3/8] net/ethoc: don't advertise gigabit on the connected PHY X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Introduce MDIO communication routines. Scan MDIO bus at reset to find attached PHYs and see if they support gigabit speeds. If they do check their gigabit control register: if gigabit autonegotiation is enabled clear it and reset the PHY. This allows using OpenCores 10/100 MAC with gigabit PHY connected to gigabit network. Signed-off-by: Max Filippov --- drivers/net/ethoc.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c index 9362faf..26b8842 100644 --- a/drivers/net/ethoc.c +++ b/drivers/net/ethoc.c @@ -290,6 +290,80 @@ static int ethoc_init_ring(struct eth_device *dev) return 0; } +#ifdef CONFIG_SYS_ETHOC_SETUP_PHY + +static u16 ethoc_mii_read(struct eth_device *dev, u8 phy, u8 reg) +{ + ulong tmo = get_timer(0); + + ethoc_write(dev, MIIADDRESS, MIIADDRESS_ADDR(phy, reg)); + ethoc_write(dev, MIICOMMAND, MIICOMMAND_READ); + + while (get_timer(tmo) < CONFIG_SYS_HZ) { + u32 status = ethoc_read(dev, MIISTATUS); + if (!(status & MIISTATUS_BUSY)) { + u32 data = ethoc_read(dev, MIIRX_DATA); + /* reset MII command register */ + ethoc_write(dev, MIICOMMAND, 0); + return data; + } + } + return 0xffff; +} + +static void ethoc_mii_write(struct eth_device *dev, u8 phy, u8 reg, u16 v) +{ + ulong tmo = get_timer(0); + + ethoc_write(dev, MIIADDRESS, MIIADDRESS_ADDR(phy, reg)); + ethoc_write(dev, MIITX_DATA, v); + ethoc_write(dev, MIICOMMAND, MIICOMMAND_WRITE); + + while (get_timer(tmo) < CONFIG_SYS_HZ) { + u32 stat = ethoc_read(dev, MIISTATUS); + if (!(stat & MIISTATUS_BUSY)) { + /* reset MII command register */ + ethoc_write(dev, MIICOMMAND, 0); + return; + } + } +} + +static void ethoc_setup_phy(struct eth_device *dev) +{ + u8 phy; + + ethoc_write(dev, MIIMODER, 0xfe); + + for (phy = 0; phy < 32; ++phy) { + if (ethoc_mii_read(dev, phy, MII_PHYSID1) != 0xffff) { + u16 v; + + v = ethoc_mii_read(dev, phy, MII_BMSR); + if (!(v & BMSR_ESTATEN)) + continue; + + v = ethoc_mii_read(dev, phy, MII_CTRL1000); + if (!(v & (ADVERTISE_1000FULL | ADVERTISE_1000HALF))) + continue; + + ethoc_mii_write(dev, phy, MII_CTRL1000, + v & ~(ADVERTISE_1000FULL | + ADVERTISE_1000HALF)); + v = ethoc_mii_read(dev, phy, MII_BMCR); + ethoc_mii_write(dev, phy, MII_BMCR, v | BMCR_RESET); + } + } +} + +#else + +static inline void ethoc_setup_phy(struct eth_device *dev) +{ +} + +#endif + static int ethoc_reset(struct eth_device *dev) { u32 mode; @@ -311,6 +385,8 @@ static int ethoc_reset(struct eth_device *dev) ethoc_write(dev, MODER, mode); ethoc_write(dev, IPGT, 0x15); + ethoc_setup_phy(dev); + ethoc_ack_irq(dev, INT_MASK_ALL); ethoc_enable_rx_and_tx(dev); return 0;