blob: e88dab10c76e5b6fb9b0ff54c15374be18a69eae [file] [log] [blame]
Stefan Roese4c835a62018-09-05 15:12:35 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018 Stefan Roese <sr@denx.de>
4 */
5
6#include <common.h>
Simon Glass91caa3b2023-08-21 21:17:01 -06007#include <event.h>
Simon Glass691d7192020-05-10 11:40:02 -06008#include <init.h>
Simon Glass336d4612020-02-03 07:36:16 -07009#include <malloc.h>
Weijie Gao9bf72ba2020-11-12 16:35:33 +080010#include <asm/addrspace.h>
Simon Glass401d1c42020-10-30 21:38:53 -060011#include <asm/global_data.h>
Simon Glasscd93d622020-05-10 11:40:13 -060012#include <linux/bitops.h>
Stefan Roese4c835a62018-09-05 15:12:35 +020013#include <linux/io.h>
14#include <linux/sizes.h>
Stefan Roese4c835a62018-09-05 15:12:35 +020015
Weijie Gao02cd4492020-04-21 09:28:34 +020016DECLARE_GLOBAL_DATA_PTR;
Stefan Roese4c835a62018-09-05 15:12:35 +020017
18int dram_init(void)
19{
Weijie Gao4bc01042022-05-20 11:22:21 +080020 gd->ram_size = get_ram_size((void *)KSEG1, CONFIG_MAX_MEM_SIZE << 20);
Stefan Roese4c835a62018-09-05 15:12:35 +020021
22 return 0;
23}
Stefan Roese9814fb22019-05-28 08:11:37 +020024
Simon Glass91caa3b2023-08-21 21:17:01 -060025#ifndef CONFIG_SPL_BUILD
26static int last_stage_init(void)
Stefan Roese9814fb22019-05-28 08:11:37 +020027{
28 void *src, *dst;
29
30 src = malloc(SZ_64K);
31 dst = malloc(SZ_64K);
32 if (!src || !dst) {
33 printf("Can't allocate buffer for cache cleanup copy!\n");
34 return 0;
35 }
36
37 /*
38 * It has been noticed, that sometimes the d-cache is not in a
39 * "clean-state" when U-Boot is running on MT7688. This was
40 * detected when using the ethernet driver (which uses d-cache)
41 * and a TFTP command does not complete. Copying an area of 64KiB
42 * in DDR at a very late bootup time in U-Boot, directly before
43 * calling into the prompt, seems to fix this issue.
44 */
45 memcpy(dst, src, SZ_64K);
46 free(src);
47 free(dst);
48
49 return 0;
50}
Simon Glass91caa3b2023-08-21 21:17:01 -060051EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init);
52#endif