From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11987C4338F for ; Sun, 15 Aug 2021 00:19:13 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3B17A60E76 for ; Sun, 15 Aug 2021 00:19:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3B17A60E76 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B285D82E2B; Sun, 15 Aug 2021 02:19:10 +0200 (CEST) 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="AdUgzslN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9650382E4A; Sun, 15 Aug 2021 02:19:09 +0200 (CEST) Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) (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 49D2782E2B for ; Sun, 15 Aug 2021 02:19:05 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mibodhi@gmail.com Received: by mail-qk1-x729.google.com with SMTP id y144so2161344qkb.6 for ; Sat, 14 Aug 2021 17:19:05 -0700 (PDT) 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=Qmz0joXEb2Jn1ckbkGE1d9CbWHavjXlrLSzCUzNIqS8=; b=AdUgzslN7n+MD5+paz9f2pgrUNxCKDzKmY/TZcvZuJ+VD9W6aKJ4fHzdIoSRoy9xqL v0iaFFNpUi2B+jfULFHMhWVneweS0exFVjOHi3REnjpASpQhQQ0ne9UW4qZX71uUY3d3 EyypXjZxDkNsFLKiPz23wdna31E6ryRIVGEL1AJqRSh4HNQtOyTRyQTUCQy84Q94RtyV wPKVk8JnLb9RLXukbVfuzGdS5AEssNx94iUhasAyI8dgxJ1n/dAEuJ9cWxpk/iE65rZr 2FcvbYBuRIrTfOHnjEVCDHU7Hxx6Yc0DxePQHLscQwsENGAzABC6VyDY5ja0hEWeQNIn R75Q== 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=Qmz0joXEb2Jn1ckbkGE1d9CbWHavjXlrLSzCUzNIqS8=; b=rilwOhe10L/tEqO+Yf6L9be5hUrH8JvbEp3v1HfocqgBxAM333YjCC710Ck+lU+P/W TPd00zBjioB7XPt6hmw+XmWUxKzqNadzuwIBR7gxsOIjSiMn5yWqVkAcU4y302P4eEzj 6oOCJJQ0br4eCe9berqqCiwnmmeUx4wd9teP1ZKl4pY+a4d3qFKeMyH83FCHzON0YIH2 uNgicRh9OGZFU6EuwLLdfDQk2guDeTt0fEnREnlZNYRFXFNXSlunmcTH1QL7wXuJ3mYV XkOaWOxlBwjgWQZBrv37FuWKpOE/QjoSZ719s6RwRj4Kl/51jlsHaM4SR/5hg8JUp366 8CKw== X-Gm-Message-State: AOAM533Tra0erAT3+7iwQPhEwwU7xKhRIclCtDiJje+2gv69dX3Q+uY5 bJt7ArEtmAKnoaglCnjGUBtfhTCslQM= X-Google-Smtp-Source: ABdhPJyCJjF51KS3ow2HUghZVfAo68XskdaaJEcSx240vFEPKHOsB/vqCNS9EuZOiS9p3QWRv9Za2Q== X-Received: by 2002:a37:7801:: with SMTP id t1mr9450582qkc.162.1628986744148; Sat, 14 Aug 2021 17:19:04 -0700 (PDT) Received: from localhost.localdomain ([66.218.48.244]) by smtp.gmail.com with ESMTPSA id x13sm2887122qki.97.2021.08.14.17.19.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Aug 2021 17:19:03 -0700 (PDT) From: Tony Dinh To: U-Boot Mailing List , Stefan Roese , Simon Glass , Ramon Fried , Joe Hershberger Cc: Tom Rini , Tony Dinh Subject: [PATCH v2 3/3] common: Add fdt network helper functions Date: Sat, 14 Aug 2021 17:17:13 -0700 Message-Id: <20210815001713.4148-3-mibodhi@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210815001713.4148-1-mibodhi@gmail.com> References: <20210806044910.23500-1-mibodhi@gmail.com> <20210815001713.4148-1-mibodhi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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.103.2 at phobos.denx.de X-Virus-Status: Clean Add fdt network helper functions fdt_support_net.c Reviewed-by: Stefan Roese Acked-by: Ramon Fried Signed-off-by: Tony Dinh --- Changes in v2: - Return FDT_ERR_NOTFOUND if fdt_get_phy_addr failed to find PHY addr - Coding standards. common/fdt_support_net.c | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 common/fdt_support_net.c diff --git a/common/fdt_support_net.c b/common/fdt_support_net.c new file mode 100644 index 0000000000..46fa12dd7c --- /dev/null +++ b/common/fdt_support_net.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2021 Tony Dinh + */ + +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +int fdt_get_phy_addr(const char *path) +{ + const void *fdt = gd->fdt_blob; + const u32 *reg; + const u32 *val; + int node, phandle, addr; + + /* Find the node by its full path */ + node = fdt_path_offset(fdt, path); + if (node >= 0) { + /* Look up phy-handle */ + val = fdt_getprop(fdt, node, "phy-handle", NULL); + if (!val) { + /* Look up phy (deprecated property for phy handle) */ + val = fdt_getprop(fdt, node, "phy", NULL); + } + if (val) { + phandle = fdt32_to_cpu(*val); + if (!phandle) + return -FDT_ERR_NOTFOUND; + + /* Follow it to its node */ + node = fdt_node_offset_by_phandle(fdt, phandle); + if (node) { + /* Look up reg */ + reg = fdt_getprop(fdt, node, "reg", NULL); + if (reg) { + addr = fdt32_to_cpu(*reg); + return addr; + } + } + } + } + return -FDT_ERR_NOTFOUND; +} -- 2.20.1