From patchwork Wed Mar 19 22:15:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 331904 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 2F1032C009A for ; Thu, 20 Mar 2014 09:16:33 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758041AbaCSWP3 (ORCPT ); Wed, 19 Mar 2014 18:15:29 -0400 Received: from quartz.orcorp.ca ([184.70.90.242]:49556 "EHLO quartz.orcorp.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757968AbaCSWP0 (ORCPT ); Wed, 19 Mar 2014 18:15:26 -0400 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=t0fTWc0tFfcffRto6c4TZ/9wxWCQ+8ArPwR1oWigNK4=; b=ZS+pmT7nDmuyqvP6vgmZ9lw9rlp8hxO7rfDcXg6caj3hhLtJMW0jU3Cx3xyilqNI4gSAzREX6INWOH8HZhhUXIC/kR+dE59I0C0y9G1kFXf9TbIZ8krZ7KjWr23Mq6MEuAY7wlxSn50kI5qlYSnp9t+Tuxf8LjoiZL4zsJ0OSSY=; 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 1WQOlh-00068L-I2; Wed, 19 Mar 2014 16:15:25 -0600 From: Jason Gunthorpe To: "David S. Miller" Cc: Rob Herring , Florian Fainelli , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 2/2] of_mdio: Allow the DT to specify the phy ID and avoid autoprobing Date: Wed, 19 Mar 2014 16:15:24 -0600 Message-Id: <1395267324-5788-2-git-send-email-jgunthorpe@obsidianresearch.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1395267324-5788-1-git-send-email-jgunthorpe@obsidianresearch.com> References: <1395267324-5788-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 Acked-by: Rob Herring --- drivers/of/of_mdio.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) For net-next v3: - Use of_property_for_each_string as per Rob Herring - Rebase+retest against 3.14-rc7 diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index 5b3c24f..9a95831 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c @@ -43,6 +43,23 @@ static void of_set_phy_supported(struct phy_device *phydev, u32 max_speed) } } +/* 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) +{ + struct property *prop; + const char *cp; + unsigned int upper, lower; + + of_property_for_each_string(device, "compatible", prop, cp) { + if (sscanf(cp, "ethernet-phy-id%4x.%4x", &upper, &lower) == 2) { + *phy_id = ((upper & 0xFFFF) << 16) | (lower & 0xFFFF); + return 0; + } + } + return -EINVAL; +} + static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *child, u32 addr) { @@ -50,11 +67,15 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi bool is_c45; int rc; u32 max_speed = 0; + u32 phy_id; 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)) return 1;