sandbox: implement invalidate_icache_all()
[platform/kernel/u-boot.git] / board / sandbox / sandbox.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2011 The Chromium OS Authors.
4  */
5
6 #include <common.h>
7 #include <cpu_func.h>
8 #include <cros_ec.h>
9 #include <dm.h>
10 #include <env_internal.h>
11 #include <init.h>
12 #include <led.h>
13 #include <os.h>
14 #include <asm/test.h>
15 #include <asm/u-boot-sandbox.h>
16
17 /*
18  * Pointer to initial global data area
19  *
20  * Here we initialize it.
21  */
22 gd_t *gd;
23
24 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
25 /* Add a simple GPIO device */
26 U_BOOT_DEVICE(gpio_sandbox) = {
27         .name = "sandbox_gpio",
28 };
29 #endif
30
31 #ifndef CONFIG_TIMER
32 /* system timer offset in ms */
33 static unsigned long sandbox_timer_offset;
34
35 void timer_test_add_offset(unsigned long offset)
36 {
37         sandbox_timer_offset += offset;
38 }
39
40 unsigned long timer_read_counter(void)
41 {
42         return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
43 }
44 #endif
45
46 /* specific order for sandbox: nowhere is the first value, used by default */
47 static enum env_location env_locations[] = {
48         ENVL_NOWHERE,
49         ENVL_EXT4,
50 };
51
52 enum env_location env_get_location(enum env_operation op, int prio)
53 {
54         if (prio >= ARRAY_SIZE(env_locations))
55                 return ENVL_UNKNOWN;
56
57         return env_locations[prio];
58 }
59
60 int dram_init(void)
61 {
62         gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
63         return 0;
64 }
65
66 int board_init(void)
67 {
68         if (IS_ENABLED(CONFIG_LED))
69                 led_default_state();
70
71         return 0;
72 }
73
74 int ft_board_setup(void *fdt, struct bd_info *bd)
75 {
76         /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/
77         return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
78 }
79
80 #ifdef CONFIG_BOARD_LATE_INIT
81 int board_late_init(void)
82 {
83         struct udevice *dev;
84         int ret;
85
86         ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
87         if (ret && ret != -ENODEV) {
88                 /* Force console on */
89                 gd->flags &= ~GD_FLG_SILENT;
90
91                 printf("cros-ec communications failure %d\n", ret);
92                 puts("\nPlease reset with Power+Refresh\n\n");
93                 panic("Cannot init cros-ec device");
94                 return -1;
95         }
96         return 0;
97 }
98 #endif