Merge tag 'u-boot-stm32-20210409' of https://source.denx.de/u-boot/custodians/u-boot-stm
[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/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
36 void timer_test_add_offset(unsigned long offset)
37 {
38         sandbox_timer_offset += offset;
39 }
40
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         ENVL_FAT,
52 };
53
54 enum env_location env_get_location(enum env_operation op, int prio)
55 {
56         if (prio >= ARRAY_SIZE(env_locations))
57                 return ENVL_UNKNOWN;
58
59         return env_locations[prio];
60 }
61
62 int dram_init(void)
63 {
64         gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
65         return 0;
66 }
67
68 int board_init(void)
69 {
70         if (IS_ENABLED(CONFIG_LED))
71                 led_default_state();
72
73         return 0;
74 }
75
76 int ft_board_setup(void *fdt, struct bd_info *bd)
77 {
78         /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/
79         return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
80 }
81
82 #ifdef CONFIG_BOARD_LATE_INIT
83 int board_late_init(void)
84 {
85         struct udevice *dev;
86         int ret;
87
88         ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
89         if (ret && ret != -ENODEV) {
90                 /* Force console on */
91                 gd->flags &= ~GD_FLG_SILENT;
92
93                 printf("cros-ec communications failure %d\n", ret);
94                 puts("\nPlease reset with Power+Refresh\n\n");
95                 panic("Cannot init cros-ec device");
96                 return -1;
97         }
98         return 0;
99 }
100 #endif