diff options
Diffstat (limited to 'arch/m68k/lib')
-rw-r--r-- | arch/m68k/lib/Makefile | 1 | ||||
-rw-r--r-- | arch/m68k/lib/fec.c | 79 | ||||
-rw-r--r-- | arch/m68k/lib/time.c | 63 |
3 files changed, 80 insertions, 63 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 diff --git a/arch/m68k/lib/time.c b/arch/m68k/lib/time.c index 8957d194d4..bde1f4c228 100644 --- a/arch/m68k/lib/time.c +++ b/arch/m68k/lib/time.c @@ -110,69 +110,6 @@ ulong get_timer(ulong base) #endif /* CONFIG_MCFTMR */ -#if defined(CONFIG_MCFPIT) -#if !defined(CONFIG_SYS_PIT_BASE) -# error "CONFIG_SYS_PIT_BASE not defined!" -#endif - -static unsigned short lastinc; - -void __udelay(unsigned long usec) -{ - volatile pit_t *timerp = (pit_t *) (CONFIG_SYS_UDELAY_BASE); - uint tmp; - - while (usec > 0) { - if (usec > 65000) - tmp = 65000; - else - tmp = usec; - usec = usec - tmp; - - /* Set up TIMER 3 as timebase clock */ - timerp->pcsr = PIT_PCSR_OVW; - timerp->pmr = 0; - /* set period to 1 us */ - timerp->pcsr |= PIT_PCSR_PRE(CONFIG_SYS_PIT_PRESCALE) | PIT_PCSR_EN; - - timerp->pmr = tmp; - while (timerp->pcntr > 0) ; - } -} - -void timer_init(void) -{ - volatile pit_t *timerp = (pit_t *) (CONFIG_SYS_PIT_BASE); - timestamp = 0; - - /* Set up TIMER 4 as poll clock */ - timerp->pcsr = PIT_PCSR_OVW; - timerp->pmr = lastinc = 0; - timerp->pcsr |= PIT_PCSR_PRE(CONFIG_SYS_PIT_PRESCALE) | PIT_PCSR_EN; - - return 0; -} - -ulong get_timer(ulong base) -{ - unsigned short now, diff; - volatile pit_t *timerp = (pit_t *) (CONFIG_SYS_PIT_BASE); - - now = timerp->pcntr; - diff = -(now - lastinc); - - timestamp += diff; - lastinc = now; - return timestamp - base; -} - -void wait_ticks(unsigned long ticks) -{ - u32 start = get_timer(0); - while (get_timer(start) < ticks) ; -} -#endif /* CONFIG_MCFPIT */ - /* * This function is derived from PowerPC code (read timebase as long long). * On M68K it just returns the timer value. |