From patchwork Tue Feb 16 22:48:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 1441144 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=oCB2i0IS; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DgGP921NVz9sCD for ; Wed, 17 Feb 2021 09:49:17 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 179CB82849; Tue, 16 Feb 2021 23:48:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="oCB2i0IS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 09CCA82717; Tue, 16 Feb 2021 23:48:41 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 46C6C827F6 for ; Tue, 16 Feb 2021 23:48:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=olteanv@gmail.com Received: by mail-ej1-x632.google.com with SMTP id i23so12909005ejg.10 for ; Tue, 16 Feb 2021 14:48:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vlIsVZT1kjCITut3hhQWPPztLV1HB7MhlSwmVue5LD4=; b=oCB2i0ISSkfQtQCjpMU04Ei+xMMXXjgM+Sdnjn+cWBoIxS6pidQNRArVV5gNFVBIIM 0AIkRrMN9Vl2fatStHH5JVlBEXnAa8zK0LavP+uPs6m3Vild/uPhz12fh1yGM5ChaUzC fHB9/UHpzSa2Wo7Im7G+y5meIyPQGK39lZ8Eu+oG5YEbhf59cpv+GCLSKlYVfeYr+B/i RAq+Trndxa2PgVm+IsR8OhkWC+wrpkf8+T9apbdPB3fEvjd7NflnGrnLeF0AZgHpFFo2 jv+6lAB29aOhW3nYsNjfgsqrASzF/dgO+YhfNJ5KNTw3TPDK1KvvjLVESvAIYDmNZZst iXrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vlIsVZT1kjCITut3hhQWPPztLV1HB7MhlSwmVue5LD4=; b=GVvRU1k7z0SJcXftwlM7R6GJDZDu/x46M0jj5Et3oQoCYv+TJEeUk6YvXDdxttf/aa pPR5ZOHi5+qJwZKhRwP9+od/IHWdCwEhi+reYXfwPVTm2m5eagq+sSK906s+iWK+lAWA 51aWuuIQIngwbtNzSDDQ7qZXzlVgLRFXLFmqVDB7IML5Z7t2JXFhCKZi4V8HV3eP+5kP wiHLnjTEZuGX3yxVpOGXchQZ0BGmhdwJ40QQUeA7P62C/nK2nKoSR/tYaRrbt3EJbogn Pqj9wK0shpJmn0el1PksOIOmL90y9U1sE6Ih/d4n/E1/ewLa+KAXIpCZ50RDVwPmhjZb Snqw== X-Gm-Message-State: AOAM5328W0jC64MroNQLaa9r5VT3yoq7Zk0Lm5FqN94y0g4kvwdG6Ion yKk8iOTSY94tBBqndvgUfCg= X-Google-Smtp-Source: ABdhPJzme6u/TSL7YeOiIt2mVHmOF28dsl3ZkWTJvBQqZuFh/MzrYhTTRmRidmHHft8K9OVCLfzKzw== X-Received: by 2002:a17:906:1d44:: with SMTP id o4mr19876336ejh.130.1613515713941; Tue, 16 Feb 2021 14:48:33 -0800 (PST) Received: from localhost.localdomain (5-12-227-87.residential.rdsnet.ro. [5.12.227.87]) by smtp.gmail.com with ESMTPSA id bf8sm106096edb.34.2021.02.16.14.48.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Feb 2021 14:48:33 -0800 (PST) From: Vladimir Oltean To: Tom Rini , Joe Hershberger , Simon Glass , Bin Meng , u-boot@lists.denx.de Cc: Michael Walle , Alexandru Marginean , Claudiu Manoil , Priyanka Jain Subject: [PATCH 3/4] net: mdio: teach dm_eth_phy_connect to connect to fixed PHY Date: Wed, 17 Feb 2021 00:48:03 +0200 Message-Id: <20210216224804.3355044-4-olteanv@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210216224804.3355044-1-olteanv@gmail.com> References: <20210216224804.3355044-1-olteanv@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean From: Vladimir Oltean It would be desirable for top-level callers of PHYLIB to deal with as little complexity as possible, and when they call dm_eth_phy_connect, they get a struct phy_device that "just works". There is a phy_connect_fixed interception put in phy_connect, however dm_eth_phy_connect will not reach there: if will search for a phy-handle all by itself, and error out if there isn't one. So we can make callers of dm_eth_phy_connect suffer by having them call: err = dm_eth_phy_connect(); if (err) err = dm_eth_phy_connect_fixed(); or we can just add the logic in dm_eth_phy_connect() that searches for a fixed-link before searching for a phy-handle. In fact we already have an in-tree driver that can make use of this refactoring: the Freescale TSEC driver. Signed-off-by: Vladimir Oltean --- drivers/net/tsec.c | 6 +----- net/mdio-uclass.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index ec4868937257..f801d020fb65 100644 --- a/drivers/net/tsec.c +++ b/drivers/net/tsec.c @@ -707,11 +707,7 @@ static int init_phy(struct tsec_private *priv) tsec_configure_serdes(priv); #if defined(CONFIG_DM_ETH) && defined(CONFIG_DM_MDIO) - if (ofnode_valid(ofnode_find_subnode(dev_ofnode(priv->dev), - "fixed-link"))) - phydev = phy_connect(NULL, 0, priv->dev, priv->interface); - else - phydev = dm_eth_phy_connect(priv->dev); + phydev = dm_eth_phy_connect(priv->dev); #else phydev = phy_connect(priv->bus, priv->phyaddr, priv->dev, priv->interface); diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c index 697e5f838d94..766d4711cc23 100644 --- a/net/mdio-uclass.c +++ b/net/mdio-uclass.c @@ -177,9 +177,10 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev, /* Connect to a PHY linked in eth DT node */ struct phy_device *dm_eth_phy_connect(struct udevice *ethdev) { - const char *if_str; + ofnode node = dev_ofnode(ethdev), subnode; phy_interface_t interface; struct phy_device *phy; + const char *if_str; int i; if (!dev_has_ofnode(ethdev)) { @@ -200,7 +201,14 @@ struct phy_device *dm_eth_phy_connect(struct udevice *ethdev) if (interface == PHY_INTERFACE_MODE_NONE) dev_dbg(ethdev, "can't find interface mode, default to NONE\n"); - phy = dm_eth_connect_phy_handle(ethdev, interface); + subnode = ofnode_find_subnode(node, "fixed-link"); + if (ofnode_valid(subnode)) { + phy = phy_connect(NULL, 0, ethdev, interface); + if (phy) + phy->node = subnode; + } else { + phy = dm_eth_connect_phy_handle(ethdev, interface); + } if (!phy) return NULL;