From patchwork Fri Jan 31 21:50:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 315850 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 923182C00AE for ; Sat, 1 Feb 2014 08:51:34 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933085AbaAaVvP (ORCPT ); Fri, 31 Jan 2014 16:51:15 -0500 Received: from quartz.orcorp.ca ([184.70.90.242]:36211 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932320AbaAaVvL (ORCPT ); Fri, 31 Jan 2014 16:51:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=obsidianresearch.com; s=rsa1; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=ycxqklT8ViqsXXsrIQtDkjlG/yFkV6nZzxgA4Yvb+00=; b=dd4RlZ/L30nQGaqOmhR+fb9gXe1YKa2DizOhk6U66+X4jyWTxzhwIMvkP+znf8DZ5r+BeFOEf9EU5GX1cxpCquyr+gxKzhWOSvfN3yUqk6dqjIItSMb1D6K/yvza0Te0Qd9vMQNh24ypm4T9HNImJuN5zpXYLjXYA4XRUDdk6HY=; Received: from [10.0.0.161] (helo=jggl.edm.orcorp.ca) by quartz.orcorp.ca with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1W9LzQ-0000nz-4r; Fri, 31 Jan 2014 14:51:08 -0700 From: Jason Gunthorpe To: Rob Herring Cc: Grant Likely , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 2/2] of_mdio: Allow the DT to specify the phy ID and avoid autoprobing Date: Fri, 31 Jan 2014 14:50:45 -0700 Message-Id: <1391205045-1751-2-git-send-email-jgunthorpe@obsidianresearch.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1391205045-1751-1-git-send-email-jgunthorpe@obsidianresearch.com> References: <1391205045-1751-1-git-send-email-jgunthorpe@obsidianresearch.com> X-Broken-Reverse-DNS: no host name found for IP address 10.0.0.161 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This makes the generic of_mdiobus_register parse the DT compatible string for the pattern ethernet-phy-idAAAA.BBBB. If present it should be a value that matches the phy-id register normally readable through MDIO. When the ID is given the phy autoprobing is defeated and the phy is created directly. This is necessary to support phy's that cannot be autoprobed when of_mdiobus_register is called. Specifically, my case has the phy in reset at of_mdiobus_register, the reset is only released once the ethernet driver starts, before it attaches to the phy. Tested on ARM Kirkwood with phy id 0x01410e90 (Marvell 88E1318) Signed-off-by: Jason Gunthorpe Acked-by: Florian Fainelli --- drivers/of/of_mdio.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index d5a57a9..c93287e 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c @@ -22,6 +22,30 @@ MODULE_AUTHOR("Grant Likely "); MODULE_LICENSE("GPL"); +/* Extract the clause 22 phy ID from the compatible string of the form + * ethernet-phy-idAAAA.BBBB */ +static int of_get_phy_id(struct device_node *device, u32 *phy_id) +{ + const char *cp; + int cplen, l; + unsigned int upper, lower; + + cp = of_get_property(device, "compatible", &cplen); + if (cp == NULL) + return -EINVAL; + while (cplen > 0) { + if (sscanf(cp, "ethernet-phy-id%4x.%4x", &upper, &lower) == 2) { + *phy_id = ((upper & 0xFFFF) << 16) | (lower & 0xFFFF); + return 0; + } + + l = strlen(cp) + 1; + cp += l; + cplen -= l; + } + return -EINVAL; +} + /** * of_mdiobus_register - Register mii_bus and create PHYs from the device tree * @mdio: pointer to mii_bus structure @@ -36,6 +60,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) struct device_node *child; const __be32 *paddr; u32 addr; + u32 phy_id; bool is_c45, scanphys = false; int rc, i, len; @@ -81,7 +106,10 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) is_c45 = of_device_is_compatible(child, "ethernet-phy-ieee802.3-c45"); - phy = get_phy_device(mdio, addr, is_c45); + if (!is_c45 && !of_get_phy_id(child, &phy_id)) + phy = phy_device_create(mdio, addr, phy_id, 0, NULL); + else + phy = get_phy_device(mdio, addr, is_c45); if (!phy || IS_ERR(phy)) { dev_err(&mdio->dev,