From patchwork Tue Oct 23 02:40:46 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Troy Kisky X-Patchwork-Id: 193321 X-Patchwork-Delegate: sbabic@denx.de 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 4177C2C017D for ; Tue, 23 Oct 2012 13:43:15 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5431D4A234; Tue, 23 Oct 2012 04:42:24 +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 I3VWp5CFbIxj; Tue, 23 Oct 2012 04:42:24 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CB2184A2BC; Tue, 23 Oct 2012 04:41:42 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A3DF94A242 for ; Tue, 23 Oct 2012 04:41:07 +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 WZkFRTqegoEj for ; Tue, 23 Oct 2012 04:41:05 +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-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) by theia.denx.de (Postfix) with ESMTPS id C76A14A231 for ; Tue, 23 Oct 2012 04:40:55 +0200 (CEST) Received: by mail-pa0-f44.google.com with SMTP id fb11so2233568pad.3 for ; Mon, 22 Oct 2012 19:40:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=xOKnY0QRiNOrcK1SrgJt5Jt7ZU1GrfD64rvVzC1sbnk=; b=m9CX3U+tg9eimtI06rdvYUEw2VRJNF8t6sYDuKJT3iRvunrF6HIxfEwfJykKqfIQuV ahf6BEixoRjpfwRC/sDN3U1RcrC8quz3DJg/P9iKa3BrQbVCV0mtS3/M8NJIO3poN8Y4 Qhc6TEuut+LeNsC2pp8qvp98wOb2y+4uGhMaeTLsw5CCXo3I7XD8y+jb6POJB+tOLoea 4H4WIZKEEarMdlAQB/AxL4MwsLWIXK601gR/HH0eA1MCFgwMRFti4VIHR+VvKl2BxdmO R64VNH0Dgp3mH+I+3ywpZH9z06O12TWHtsmVH7fbWgGBjr13O/8wkQkP4NslBIg56yXu kqVg== Received: by 10.68.125.229 with SMTP id mt5mr35495662pbb.51.1350960053459; Mon, 22 Oct 2012 19:40:53 -0700 (PDT) Received: from officeserver-2 ([70.96.116.236]) by mx.google.com with ESMTPS id mz10sm6877053pbc.37.2012.10.22.19.40.50 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 22 Oct 2012 19:40:51 -0700 (PDT) Received: from tkisky by officeserver-2 with local (Exim 4.76) (envelope-from ) id 1TQUQj-00066X-GK; Mon, 22 Oct 2012 19:41:21 -0700 From: Troy Kisky To: u-boot@lists.denx.de, Joe Hershberger , sbabic@denx.de, dirk.behme@googlemail.com Date: Mon, 22 Oct 2012 19:40:46 -0700 Message-Id: <1350960047-23404-9-git-send-email-troy.kisky@boundarydevices.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1350960047-23404-1-git-send-email-troy.kisky@boundarydevices.com> References: <1345502918-18305-1-git-send-email-troy.kisky@boundarydevices.com> <1350960047-23404-1-git-send-email-troy.kisky@boundarydevices.com> X-Gm-Message-State: ALoCoQmDgLpm3Ur7+PV6KMn7OwlxXIorqxK5FSfDdZNpUAbrMYNO13b8keeCggqfhwKmxPtX5n9N Cc: afleming@gmail.com Subject: [U-Boot] [PATCH V3 8/9] net: fec_mxc: get phydev before fec_probe 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 Signed-off-by: Troy Kisky --- drivers/net/fec_mxc.c | 117 +++++++++++++++++++++++++++++++------------------ drivers/net/fec_mxc.h | 2 +- include/netdev.h | 7 +++ 3 files changed, 83 insertions(+), 43 deletions(-) diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c index 913c561..4dbcdca 100644 --- a/drivers/net/fec_mxc.c +++ b/drivers/net/fec_mxc.c @@ -901,12 +901,16 @@ static void fec_set_dev_name(char *dest, int dev_id) sprintf(dest, (dev_id == -1) ? "FEC" : "FEC%i", dev_id); } -static int fec_probe(bd_t *bd, int dev_id, int phy_id, uint32_t base_addr) +#ifdef CONFIG_PHYLIB +int fec_probe(bd_t *bd, int dev_id, uint32_t base_addr, + struct mii_dev *bus, struct phy_device *phydev) +#else +static int fec_probe(bd_t *bd, int dev_id, uint32_t base_addr, + struct mii_dev *bus, int phy_id) +#endif { - struct phy_device *phydev; struct eth_device *edev; struct fec_priv *fec; - struct mii_dev *bus; unsigned char ethaddr[6]; uint32_t start; int ret = 0; @@ -953,69 +957,98 @@ static int fec_probe(bd_t *bd, int dev_id, int phy_id, uint32_t base_addr) } fec_reg_setup(fec); - fec_set_dev_name(edev->name, dev_id); fec->dev_id = (dev_id == -1) ? 0 : dev_id; + fec->bus = bus; + fec_mii_setspeed(bus->priv); +#ifdef CONFIG_PHYLIB + fec->phydev = phydev; + phy_connect_dev(phydev, edev); + /* Configure phy */ + phy_config(phydev); +#else fec->phy_id = phy_id; +#endif + eth_register(edev); + + if (fec_get_hwaddr(edev, dev_id, ethaddr) == 0) { + debug("got MAC%d address from fuse: %pM\n", dev_id, ethaddr); + memcpy(edev->enetaddr, ethaddr, 6); + } + return ret; +err3: + free(fec); +err2: + free(edev); +err1: + return ret; +} + +struct mii_dev *fec_get_miibus(uint32_t base_addr, int dev_id) +{ + struct ethernet_regs *eth = (struct ethernet_regs *)base_addr; + struct mii_dev *bus; + int ret; bus = mdio_alloc(); if (!bus) { printf("mdio_alloc failed\n"); - ret = -ENOMEM; - goto err3; + return NULL; } bus->read = fec_phy_read; bus->write = fec_phy_write; + bus->priv = eth; fec_set_dev_name(bus->name, dev_id); + + ret = mdio_register(bus); + if (ret) { + printf("mdio_register failed\n"); + free(bus); + return NULL; + } + fec_mii_setspeed(eth); + return bus; +} + +int fecmxc_initialize_multi(bd_t *bd, int dev_id, int phy_id, uint32_t addr) +{ + uint32_t base_mii; + struct mii_dev *bus = NULL; +#ifdef CONFIG_PHYLIB + struct phy_device *phydev = NULL; +#endif + int ret; + #ifdef CONFIG_MX28 /* * The i.MX28 has two ethernet interfaces, but they are not equal. * Only the first one can access the MDIO bus. */ - bus->priv = (struct ethernet_regs *)MXS_ENET0_BASE; + base_mii = MXS_ENET0_BASE; #else - bus->priv = fec->eth; + base_mii = addr; #endif - fec_mii_setspeed(bus->priv); - ret = mdio_register(bus); - if (ret) { - printf("mdio_register failed\n"); - free(bus); - ret = -ENOMEM; - goto err3; - } - fec->bus = bus; - eth_register(edev); - - if (fec_get_hwaddr(edev, dev_id, ethaddr) == 0) { - debug("got MAC%d address from fuse: %pM\n", dev_id, ethaddr); - memcpy(edev->enetaddr, ethaddr, 6); - } - /* Configure phy */ + debug("eth_init: fec_probe(bd, %i, %i) @ %08x\n", dev_id, phy_id, addr); + bus = fec_get_miibus(base_mii, dev_id); + if (!bus) + return -ENOMEM; #ifdef CONFIG_PHYLIB - phydev = phy_connect(fec->bus, phy_id, edev, PHY_INTERFACE_MODE_RGMII); + phydev = phy_find_by_mask(bus, 1 << phy_id, PHY_INTERFACE_MODE_RGMII); if (!phydev) { free(bus); - ret = -ENOMEM; - goto err3; + return -ENOMEM; } - fec->phydev = phydev; - phy_config(phydev); + ret = fec_probe(bd, dev_id, addr, bus, phydev); +#else + ret = fec_probe(bd, dev_id, addr, bus, phy_id); #endif + if (ret) { +#ifdef CONFIG_PHYLIB + free(phydev); +#endif + free(bus); + } return ret; - -err3: - free(fec); -err2: - free(edev); -err1: - return ret; -} - -int fecmxc_initialize_multi(bd_t *bd, int dev_id, int phy_id, uint32_t addr) -{ - debug("eth_init: fec_probe(bd, %i, %i) @ %08x\n", dev_id, phy_id, addr); - return fec_probe(bd, dev_id, phy_id, addr); } #ifdef CONFIG_FEC_MXC_PHYADDR diff --git a/drivers/net/fec_mxc.h b/drivers/net/fec_mxc.h index 203285a..b8f0da3 100644 --- a/drivers/net/fec_mxc.h +++ b/drivers/net/fec_mxc.h @@ -271,11 +271,11 @@ struct fec_priv { bd_t *bd; uint8_t *tdb_ptr; int dev_id; - int phy_id; struct mii_dev *bus; #ifdef CONFIG_PHYLIB struct phy_device *phydev; #else + int phy_id; int (*mii_postcall)(int); #endif }; diff --git a/include/netdev.h b/include/netdev.h index b8d303d..62aef79 100644 --- a/include/netdev.h +++ b/include/netdev.h @@ -204,9 +204,16 @@ struct mv88e61xx_config { int mv88e61xx_switch_initialize(struct mv88e61xx_config *swconfig); #endif /* CONFIG_MV88E61XX_SWITCH */ +struct mii_dev *fec_get_miibus(uint32_t base_addr, int dev_id); +#ifdef CONFIG_PHYLIB +struct phy_device; +int fec_probe(bd_t *bd, int dev_id, uint32_t base_addr, + struct mii_dev *bus, struct phy_device *phydev); +#else /* * Allow FEC to fine-tune MII configuration on boards which require this. */ int fecmxc_register_mii_postcall(struct eth_device *dev, int (*cb)(int)); +#endif #endif /* _NETDEV_H_ */