xref: /openbmc/u-boot/board/sandbox/sandbox.c (revision ef64e782)
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 	if (cros_ec_get_error()) {
63 		/* Force console on */
64 		gd->flags &= ~GD_FLG_SILENT;
65 
66 		printf("cros-ec communications failure %d\n",
67 		       cros_ec_get_error());
68 		puts("\nPlease reset with Power+Refresh\n\n");
69 		panic("Cannot init cros-ec device");
70 		return -1;
71 	}
72 	return 0;
73 }
74 #endif
75