1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) 2019 Angelo Dureghello <angelo.dureghello@timesys.com>
7 #include <asm/global_data.h>
8 #include <linux/libfdt.h>
9 #include <fdt_support.h>
11 DECLARE_GLOBAL_DATA_PTR;
13 #if defined(CONFIG_MCFFEC) || defined(CONFIG_FSLDMAFEC)
14 static int fec_get_node(int fec_idx)
16 char fec_alias[5] = {"fec"};
21 puts("Invalid MII base index");
25 fec_alias[3] = fec_idx + '0';
27 path = fdt_get_alias(gd->fdt_blob, fec_alias);
29 puts("Invalid MII path");
33 node = fdt_path_offset(gd->fdt_blob, path);
40 int fec_get_fdt_prop(int fec_idx, const char *prop, u32 *value)
45 node = fec_get_node(fec_idx);
49 val = fdt_getprop(gd->fdt_blob, node, prop, NULL);
53 *value = fdt32_to_cpu(*val);
58 int fec_get_base_addr(int fec_idx, u32 *fec_iobase)
64 node = fec_get_node(fec_idx);
68 addr = fdtdec_get_addr_size(gd->fdt_blob, node, "reg", &size);
70 *fec_iobase = (u32)addr;
75 int fec_get_mii_base(int fec_idx, u32 *mii_base)
77 return fec_get_fdt_prop(fec_idx, "mii-base", mii_base);
80 #endif //CONFIG_MCFFEC || CONFIG_FSLDMAFEC