137200301874a5514844c2d269334cf5b490c613
[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 <init.h>
11 #include <led.h>
12 #include <os.h>
13 #include <asm/test.h>
14 #include <asm/u-boot-sandbox.h>
15
16 /*
17  * Pointer to initial global data area
18  *
19  * Here we initialize it.
20  */
21 gd_t *gd;
22
23 /* Add a simple GPIO device */
24 U_BOOT_DEVICE(gpio_sandbox) = {
25         .name = "gpio_sandbox",
26 };
27
28 void flush_cache(unsigned long start, unsigned long size)
29 {
30 }
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 int dram_init(void)
48 {
49         gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
50         return 0;
51 }
52
53 int board_init(void)
54 {
55         if (IS_ENABLED(CONFIG_LED))
56                 led_default_state();
57
58         return 0;
59 }
60
61 int ft_board_setup(void *fdt, bd_t *bd)
62 {
63         /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/
64         return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
65 }
66
67 #ifdef CONFIG_BOARD_LATE_INIT
68 int board_late_init(void)
69 {
70         struct udevice *dev;
71         int ret;
72
73         ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
74         if (ret && ret != -ENODEV) {
75                 /* Force console on */
76                 gd->flags &= ~GD_FLG_SILENT;
77
78                 printf("cros-ec communications failure %d\n", ret);
79                 puts("\nPlease reset with Power+Refresh\n\n");
80                 panic("Cannot init cros-ec device");
81                 return -1;
82         }
83         return 0;
84 }
85 #endif