xref: /openbmc/u-boot/board/sandbox/sandbox.c (revision cd71b1d5)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2011 The Chromium OS Authors.
4  */
5 
6 #include <common.h>
7 #include <cros_ec.h>
8 #include <dm.h>
9 #include <led.h>
10 #include <os.h>
11 #include <asm/test.h>
12 #include <asm/u-boot-sandbox.h>
13 
14 /*
15  * Pointer to initial global data area
16  *
17  * Here we initialize it.
18  */
19 gd_t *gd;
20 
21 /* Add a simple GPIO device */
22 U_BOOT_DEVICE(gpio_sandbox) = {
23 	.name = "gpio_sandbox",
24 };
25 
26 void flush_cache(unsigned long start, unsigned long size)
27 {
28 }
29 
30 #ifndef CONFIG_TIMER
31 /* system timer offset in ms */
32 static unsigned long sandbox_timer_offset;
33 
34 void sandbox_timer_add_offset(unsigned long offset)
35 {
36 	sandbox_timer_offset += offset;
37 }
38 
39 unsigned long timer_read_counter(void)
40 {
41 	return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
42 }
43 #endif
44 
45 int dram_init(void)
46 {
47 	gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
48 	return 0;
49 }
50 
51 int board_init(void)
52 {
53 	if (IS_ENABLED(CONFIG_LED))
54 		led_default_state();
55 
56 	return 0;
57 }
58 
59 #ifdef CONFIG_BOARD_LATE_INIT
60 int board_late_init(void)
61 {
62 	struct udevice *dev;
63 	int ret;
64 
65 	ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
66 	if (ret && ret != -ENODEV) {
67 		/* Force console on */
68 		gd->flags &= ~GD_FLG_SILENT;
69 
70 		printf("cros-ec communications failure %d\n", ret);
71 		puts("\nPlease reset with Power+Refresh\n\n");
72 		panic("Cannot init cros-ec device");
73 		return -1;
74 	}
75 	return 0;
76 }
77 #endif
78