public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tony Dinh <mibodhi@gmail.com>
To: U-Boot Mailing List <u-boot@lists.denx.de>,
	Stefan Roese <sr@denx.de>, Simon Glass <sjg@chromium.org>,
	Ramon Fried <rfried.dev@gmail.com>,
	Joe Hershberger <joe.hershberger@ni.com>
Cc: Tom Rini <trini@konsulko.com>, Tony Dinh <mibodhi@gmail.com>
Subject: [PATCH v2 3/3] common: Add fdt network helper functions
Date: Sat, 14 Aug 2021 17:17:13 -0700	[thread overview]
Message-ID: <20210815001713.4148-3-mibodhi@gmail.com> (raw)
In-Reply-To: <20210815001713.4148-1-mibodhi@gmail.com>

Add fdt network helper functions fdt_support_net.c

Reviewed-by: Stefan Roese <sr@denx.de>
Acked-by: Ramon Fried <rfried.dev@gmail.com>

Signed-off-by: Tony Dinh <mibodhi@gmail.com>
---

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 <mibodhi@gmail.com>
+ */
+
+#include <asm/global_data.h>
+#include <fdt_support.h>
+#include <fdt_support_net.h>
+#include <linux/libfdt.h>
+
+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


  parent reply	other threads:[~2021-08-15  0:19 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-06  4:49 [PATCH 0/3] common: Add fdt network helper Tony Dinh
2021-08-06  4:49 ` [PATCH 1/3] Add fdt network helper header file Tony Dinh
2021-08-12  6:17   ` Stefan Roese
2021-08-13 22:26   ` Ramon Fried
2021-09-25 15:15   ` Simon Glass
2021-08-06  4:49 ` [PATCH 2/3] Add fdt network helper functions Tony Dinh
2021-08-12  6:15   ` Stefan Roese
2021-08-12  9:12     ` Tony Dinh
2021-08-13 22:27       ` Ramon Fried
2021-08-06  4:49 ` [PATCH 3/3] Add fdt network helper to Makefile Tony Dinh
2021-08-12  6:17   ` Stefan Roese
2021-08-13 22:28   ` Ramon Fried
2021-08-12  6:18 ` [PATCH 0/3] common: Add fdt network helper Stefan Roese
2021-08-15  0:17 ` [PATCH v2 1/3] " Tony Dinh
2021-08-15  0:17   ` [PATCH v2 2/3] common: Add fdt network helper header file Tony Dinh
2021-08-15  0:17   ` Tony Dinh [this message]
2021-08-15 14:09 ` [PATCH 0/3] common: Add fdt network helper Simon Glass
2021-08-15 21:27   ` Tony Dinh
2021-08-16 23:36     ` Tony Dinh
2021-08-17 16:09     ` Simon Glass
2021-08-27  4:00       ` Tony Dinh
2021-09-01  9:21         ` Tony Dinh
2021-09-02 16:41           ` Simon Glass
2021-09-03  2:24             ` Tony Dinh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210815001713.4148-3-mibodhi@gmail.com \
    --to=mibodhi@gmail.com \
    --cc=joe.hershberger@ni.com \
    --cc=rfried.dev@gmail.com \
    --cc=sjg@chromium.org \
    --cc=sr@denx.de \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox