From patchwork Fri Jun 26 22:29:45 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 29215 X-Patchwork-Delegate: galak@kernel.crashing.org 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 D89FFB70EA for ; Sat, 27 Jun 2009 08:30:44 +1000 (EST) Received: by ozlabs.org (Postfix) id C68E4DDD1C; Sat, 27 Jun 2009 08:30:44 +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 81796DDD1B for ; Sat, 27 Jun 2009 08:30:44 +1000 (EST) Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by bilbo.ozlabs.org (Postfix) with ESMTP id DE76AB73BA for ; Sat, 27 Jun 2009 08:29:56 +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 21323B7091 for ; Sat, 27 Jun 2009 08:29:48 +1000 (EST) Received: by ozlabs.org (Postfix) id 1583FDDD0B; Sat, 27 Jun 2009 08:29:48 +1000 (EST) Delivered-To: linuxppc-dev@ozlabs.org Received: from buildserver.ru.mvista.com (unknown [213.79.90.228]) by ozlabs.org (Postfix) with ESMTP id 3A8B4DDD04 for ; Sat, 27 Jun 2009 08:29:47 +1000 (EST) Received: from localhost (unknown [10.150.0.9]) by buildserver.ru.mvista.com (Postfix) with ESMTP id C023D8822; Sat, 27 Jun 2009 03:29:45 +0500 (SAMST) Date: Sat, 27 Jun 2009 02:29:45 +0400 From: Anton Vorontsov To: David Miller Subject: [PATCH 1/4] of/mdio: Add fixed link support Message-ID: <20090626222945.GA32487@oksana.dev.rtsoft.ru> References: <20090626222900.GA14594@oksana.dev.rtsoft.ru> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20090626222900.GA14594@oksana.dev.rtsoft.ru> User-Agent: Mutt/1.5.20 (2009-06-14) Cc: netdev@vger.kernel.org, Li Yang , Andy Fleming , linuxppc-dev@ozlabs.org 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: , Sender: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Currently the fixed link support is broken for all OF ethernet drivers, an "OF MDIO rework" removed most of the support. Instead of re-adding fixed-link stuff to the drivers, add the support to a framework, so we won't duplicate any code. With this patch, if a node pointer is NULL, then of_phy_connect() will try to find ethernet device's node, then will look for fixed-link property, and if specified, it connects PHY as usual, via bus_id (fixed link PHYs do not have any device tree nodes associated with them). Signed-off-by: Anton Vorontsov --- drivers/of/of_mdio.c | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 41 insertions(+), 4 deletions(-) diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index aee967d..cfd876a 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c @@ -9,6 +9,10 @@ * out of the OpenFirmware device tree and using it to populate an mii_bus. */ +#include +#include +#include +#include #include #include #include @@ -129,11 +133,44 @@ struct phy_device *of_phy_connect(struct net_device *dev, void (*hndlr)(struct net_device *), u32 flags, phy_interface_t iface) { - struct phy_device *phy = of_phy_find_device(phy_np); + struct phy_device *phy = NULL; + + if (phy_np) { + int ret; + + phy = of_phy_find_device(phy_np); + if (!phy) + return NULL; + + ret = phy_connect_direct(dev, phy, hndlr, flags, iface); + if (ret) + return NULL; + } else if (dev->dev.parent) { + struct device_node *net_np; + const u32 *phy_id; + char *bus_id; + int sz; + + net_np = dev_archdata_get_node(&dev->dev.parent->archdata); + if (!net_np) + return NULL; + + phy_id = of_get_property(net_np, "fixed-link", &sz); + if (!phy_id || sz < sizeof(*phy_id)) + return NULL; + + bus_id = kasprintf(GFP_KERNEL, PHY_ID_FMT, "0", phy_id[0]); + if (!bus_id) { + dev_err(&dev->dev, "could not allocate memory\n"); + return NULL; + } - if (!phy) - return NULL; + phy = phy_connect(dev, bus_id, hndlr, 0, iface); + kfree(bus_id); + if (IS_ERR(phy)) + return NULL; + } - return phy_connect_direct(dev, phy, hndlr, flags, iface) ? NULL : phy; + return phy; } EXPORT_SYMBOL(of_phy_connect);