Merge tag 'u-boot-rockchip-20201031' of https://gitlab.denx.de/u-boot/custodians...
[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 void flush_cache(unsigned long start, unsigned long size)
32 {
33 }
34
35 #ifndef CONFIG_TIMER
36 /* system timer offset in ms */
37 static unsigned long sandbox_timer_offset;
38
39 void timer_test_add_offset(unsigned long offset)
40 {
41         sandbox_timer_offset += offset;
42 }
43
44 unsigned long timer_read_counter(void)
45 {
46         return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
47 }
48 #endif
49
50 /* specific order for sandbox: nowhere is the first value, used by default */
51 static enum env_location env_locations[] = {
52         ENVL_NOWHERE,
53         ENVL_EXT4,
54 };
55
56 enum env_location env_get_location(enum env_operation op, int prio)
57 {
58         if (prio >= ARRAY_SIZE(env_locations))
59                 return ENVL_UNKNOWN;
60
61         return env_locations[prio];
62 }
63
64 int dram_init(void)
65 {
66         gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
67         return 0;
68 }
69
70 int board_init(void)
71 {
72         if (IS_ENABLED(CONFIG_LED))
73                 led_default_state();
74
75         return 0;
76 }
77
78 int ft_board_setup(void *fdt, struct bd_info *bd)
79 {
80         /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/
81         return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
82 }
83
84 #ifdef CONFIG_BOARD_LATE_INIT
85 int board_late_init(void)
86 {
87         struct udevice *dev;
88         int ret;
89
90         ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
91         if (ret && ret != -ENODEV) {
92                 /* Force console on */
93                 gd->flags &= ~GD_FLG_SILENT;
94
95                 printf("cros-ec communications failure %d\n", ret);
96                 puts("\nPlease reset with Power+Refresh\n\n");
97                 panic("Cannot init cros-ec device");
98                 return -1;
99         }
100         return 0;
101 }
102 #endif