From patchwork Wed Jan 30 12:54:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Andrey X-Patchwork-Id: 216920 X-Patchwork-Delegate: joe.hershberger@gmail.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 5A9992C0084 for ; Thu, 31 Jan 2013 00:48:17 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 725704A0B3; Wed, 30 Jan 2013 14:48:02 +0100 (CET) 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 0OqVot2u91kE; Wed, 30 Jan 2013 14:48:02 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 274A94A0C1; Wed, 30 Jan 2013 14:47:53 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BC4274A10D for ; Wed, 30 Jan 2013 14:36:39 +0100 (CET) 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 SXyCkld0jam7 for ; Wed, 30 Jan 2013 14:36:38 +0100 (CET) X-Greylist: delayed 2489 seconds by postgrey-1.27 at theia; Wed, 30 Jan 2013 14:36:37 CET 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 wolf.netmodule.com (wolf.netmodule.com [194.29.26.243]) by theia.denx.de (Postfix) with ESMTPS id 8744F4A0F9 for ; Wed, 30 Jan 2013 14:36:37 +0100 (CET) Received: from 194-29-26-246.static.cablecom.ch ([194.29.26.246] helo=LOIRE.netmodule.intranet) by wolf.netmodule.com with esmtp id 1U0XC5-0005h4-4a; Wed, 30 Jan 2013 13:55:13 +0100 From: David Andrey To: u-boot@lists.denx.de Date: Wed, 30 Jan 2013 13:54:27 +0100 Message-Id: <1359550467-14591-1-git-send-email-david.andrey@netmodule.com> X-Mailer: git-send-email 1.7.4.1 X-Mailman-Approved-At: Wed, 30 Jan 2013 14:47:50 +0100 Cc: David Andrey , afleming@freescale.com Subject: [U-Boot] [PATCH] PHY: micrel.c: add support for KSZ9031 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 Add support for Micrel PHY KSZ9031 in phylib, including small rework for KSZ9021 to avoid code duplication Signed-off-by: David Andrey david.andrey@netmodule.com --- drivers/net/phy/micrel.c | 83 +++++++++++++++++++++++++++++++++++----------- 1 files changed, 63 insertions(+), 20 deletions(-) diff --git a/drivers/net/phy/micrel.c b/drivers/net/phy/micrel.c index 30f3264..a7d53a1 100644 --- a/drivers/net/phy/micrel.c +++ b/drivers/net/phy/micrel.c @@ -18,6 +18,7 @@ * * Copyright 2010-2011 Freescale Semiconductor, Inc. * author Andy Fleming + * (C) 2012 NetModule AG, added KSZ9031 * */ #include @@ -52,16 +53,49 @@ static struct phy_driver KS8721_driver = { }; #endif + +/** + * KSZ9021 - KSZ9031 common + */ + +#define MII_KSZ90xx_PHY_CTL 0x1f +#define MIIM_KSZ90xx_PHYCTL_1000 (1 << 6) +#define MIIM_KSZ90xx_PHYCTL_100 (1 << 5) +#define MIIM_KSZ90xx_PHYCTL_10 (1 << 4) +#define MIIM_KSZ90xx_PHYCTL_DUPLEX (1 << 3) + +/* Update speed and duplex state */ +static int ksz90xx_phy_state(struct phy_device *phydev) +{ + unsigned phy_ctl; + + phy_ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ90xx_PHY_CTL); + + if (phy_ctl & MIIM_KSZ90xx_PHYCTL_DUPLEX) + phydev->duplex = DUPLEX_FULL; + else + phydev->duplex = DUPLEX_HALF; + + if (phy_ctl & MIIM_KSZ90xx_PHYCTL_1000) + phydev->speed = SPEED_1000; + else if (phy_ctl & MIIM_KSZ90xx_PHYCTL_100) + phydev->speed = SPEED_100; + else if (phy_ctl & MIIM_KSZ90xx_PHYCTL_10) + phydev->speed = SPEED_10; + return 0; +} + + #ifdef CONFIG_PHY_MICREL_KSZ9021 -/* ksz9021 PHY Registers */ + +/* + * KSZ9031 + */ + +/* PHY Registers */ #define MII_KSZ9021_EXTENDED_CTRL 0x0b #define MII_KSZ9021_EXTENDED_DATAW 0x0c #define MII_KSZ9021_EXTENDED_DATAR 0x0d -#define MII_KSZ9021_PHY_CTL 0x1f -#define MIIM_KSZ9021_PHYCTL_1000 (1 << 6) -#define MIIM_KSZ9021_PHYCTL_100 (1 << 5) -#define MIIM_KSZ9021_PHYCTL_10 (1 << 4) -#define MIIM_KSZ9021_PHYCTL_DUPLEX (1 << 3) #define CTRL1000_PREFER_MASTER (1 << 10) #define CTRL1000_CONFIG_MASTER (1 << 11) @@ -108,21 +142,8 @@ static int ksz9021_config(struct phy_device *phydev) static int ksz9021_startup(struct phy_device *phydev) { - unsigned phy_ctl; genphy_update_link(phydev); - phy_ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_PHY_CTL); - - if (phy_ctl & MIIM_KSZ9021_PHYCTL_DUPLEX) - phydev->duplex = DUPLEX_FULL; - else - phydev->duplex = DUPLEX_HALF; - - if (phy_ctl & MIIM_KSZ9021_PHYCTL_1000) - phydev->speed = SPEED_1000; - else if (phy_ctl & MIIM_KSZ9021_PHYCTL_100) - phydev->speed = SPEED_100; - else if (phy_ctl & MIIM_KSZ9021_PHYCTL_10) - phydev->speed = SPEED_10; + ksz90xx_phy_state(phydev); return 0; } @@ -137,6 +158,27 @@ static struct phy_driver ksz9021_driver = { }; #endif +/* + * KSZ9031 + */ +static int ksz9031_startup(struct phy_device *phydev) +{ + genphy_update_link(phydev); + ksz90xx_phy_state(phydev); + return 0; +} + +static struct phy_driver ksz9031_driver = { + .name = "Micrel ksz9031", + .uid = 0x221620, + .mask = 0xfffffe, + .features = PHY_GBIT_FEATURES, + .config = &genphy_config, + .startup = &ksz9031_startup, + .shutdown = &genphy_shutdown, +}; + + int phy_micrel_init(void) { phy_register(&KSZ804_driver); @@ -145,5 +187,6 @@ int phy_micrel_init(void) #else phy_register(&KS8721_driver); #endif + phy_register(&ksz9031_driver); return 0; }