Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / arch / mips / mach-mtmips / cpu.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2018 Stefan Roese <sr@denx.de>
4  */
5
6 #include <common.h>
7 #include <init.h>
8 #include <malloc.h>
9 #include <linux/bitops.h>
10 #include <linux/io.h>
11 #include <linux/sizes.h>
12
13 DECLARE_GLOBAL_DATA_PTR;
14
15 int dram_init(void)
16 {
17 #ifdef CONFIG_SKIP_LOWLEVEL_INIT
18         gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, SZ_256M);
19 #endif
20
21         return 0;
22 }
23
24 int last_stage_init(void)
25 {
26         void *src, *dst;
27
28         src = malloc(SZ_64K);
29         dst = malloc(SZ_64K);
30         if (!src || !dst) {
31                 printf("Can't allocate buffer for cache cleanup copy!\n");
32                 return 0;
33         }
34
35         /*
36          * It has been noticed, that sometimes the d-cache is not in a
37          * "clean-state" when U-Boot is running on MT7688. This was
38          * detected when using the ethernet driver (which uses d-cache)
39          * and a TFTP command does not complete. Copying an area of 64KiB
40          * in DDR at a very late bootup time in U-Boot, directly before
41          * calling into the prompt, seems to fix this issue.
42          */
43         memcpy(dst, src, SZ_64K);
44         free(src);
45         free(dst);
46
47         return 0;
48 }