summaryrefslogtreecommitdiff
path: root/arch/m68k/lib
diff options
context:
space:
mode:
authorAngelo Durgehello <angelo.dureghello@timesys.com>2019-11-16 01:54:16 +0300
committerTom Rini <trini@konsulko.com>2020-01-10 18:25:13 +0300
commitad420937558a9b3bc0e93d9693b34f57cf4480a0 (patch)
treee036131d4e2e6056dcf0398ca51542216e91d954 /arch/m68k/lib
parentff56f2b7263fae9132c13078ccd8d9604cf1e139 (diff)
downloadu-boot-ad420937558a9b3bc0e93d9693b34f57cf4480a0.tar.xz
m68k: add dm fec support
Add architecture-related code for dm fec support. Signed-off-by: Angelo Durgehello <angelo.dureghello@timesys.com>
Diffstat (limited to 'arch/m68k/lib')
-rw-r--r--arch/m68k/lib/Makefile1
-rw-r--r--arch/m68k/lib/fec.c79
2 files changed, 80 insertions, 0 deletions
diff --git a/arch/m68k/lib/Makefile b/arch/m68k/lib/Makefile
index 254a0a3998..a040f40eb8 100644
--- a/arch/m68k/lib/Makefile
+++ b/arch/m68k/lib/Makefile
@@ -12,3 +12,4 @@ obj-y += cache.o
obj-y += interrupts.o
obj-y += time.o
obj-y += traps.o
+obj-y += fec.o
diff --git a/arch/m68k/lib/fec.c b/arch/m68k/lib/fec.c
new file mode 100644
index 0000000000..dde353ad17
--- /dev/null
+++ b/arch/m68k/lib/fec.c
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) 2019 Angelo Dureghello <angelo.dureghello@timesys.com>
+ */
+
+#include <common.h>
+#include <linux/libfdt.h>
+#include <fdt_support.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#if defined(CONFIG_MCFFEC) || defined(CONFIG_FSLDMAFEC)
+static int fec_get_node(int fec_idx)
+{
+ char fec_alias[5] = {"fec"};
+ const char *path;
+ int node;
+
+ if (fec_idx > 1) {
+ puts("Invalid MII base index");
+ return -ENOENT;
+ }
+
+ fec_alias[3] = fec_idx + '0';
+
+ path = fdt_get_alias(gd->fdt_blob, fec_alias);
+ if (!path) {
+ puts("Invalid MII path");
+ return -ENOENT;
+ }
+
+ node = fdt_path_offset(gd->fdt_blob, path);
+ if (node < 0)
+ return -ENOENT;
+
+ return node;
+}
+
+int fec_get_fdt_prop(int fec_idx, const char *prop, u32 *value)
+{
+ int node;
+ const u32 *val;
+
+ node = fec_get_node(fec_idx);
+ if (node < 0)
+ return node;
+
+ val = fdt_getprop(gd->fdt_blob, node, prop, NULL);
+ if (!val)
+ return -ENOENT;
+
+ *value = fdt32_to_cpu(*val);
+
+ return 0;
+}
+
+int fec_get_base_addr(int fec_idx, u32 *fec_iobase)
+{
+ int node;
+ fdt_size_t size;
+ fdt_addr_t addr;
+
+ node = fec_get_node(fec_idx);
+ if (node < 0)
+ return node;
+
+ addr = fdtdec_get_addr_size(gd->fdt_blob, node, "reg", &size);
+
+ *fec_iobase = (u32)addr;
+
+ return 0;
+}
+
+int fec_get_mii_base(int fec_idx, u32 *mii_base)
+{
+ return fec_get_fdt_prop(fec_idx, "mii-base", mii_base);
+}
+
+#endif //CONFIG_MCFFEC || CONFIG_FSLDMAFEC