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