Convert CONFIG_SYS_NAND_ONFI_DETECTION to Kconfig
[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 #include <malloc.h>
18
19 #include <extension_board.h>
20
21 /*
22  * Pointer to initial global data area
23  *
24  * Here we initialize it.
25  */
26 gd_t *gd;
27
28 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
29 /*
30  * Add a simple GPIO device (don't use with of-platdata as it interferes with
31  * the auto-generated devices)
32  */
33 U_BOOT_DRVINFO(gpio_sandbox) = {
34         .name = "sandbox_gpio",
35 };
36 #endif
37
38 #ifndef CONFIG_TIMER
39 /* system timer offset in ms */
40 static unsigned long sandbox_timer_offset;
41
42 void timer_test_add_offset(unsigned long offset)
43 {
44         sandbox_timer_offset += offset;
45 }
46
47 unsigned long timer_read_counter(void)
48 {
49         return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
50 }
51 #endif
52
53 /* specific order for sandbox: nowhere is the first value, used by default */
54 static enum env_location env_locations[] = {
55         ENVL_NOWHERE,
56         ENVL_EXT4,
57         ENVL_FAT,
58 };
59
60 enum env_location env_get_location(enum env_operation op, int prio)
61 {
62         if (prio >= ARRAY_SIZE(env_locations))
63                 return ENVL_UNKNOWN;
64
65         return env_locations[prio];
66 }
67
68 int dram_init(void)
69 {
70         gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
71         return 0;
72 }
73
74 int board_init(void)
75 {
76         if (IS_ENABLED(CONFIG_LED))
77                 led_default_state();
78
79         return 0;
80 }
81
82 int ft_board_setup(void *fdt, struct bd_info *bd)
83 {
84         /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/
85         return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
86 }
87
88 #ifdef CONFIG_CMD_EXTENSION
89 int extension_board_scan(struct list_head *extension_list)
90 {
91         struct extension *extension;
92         int i;
93
94         for (i = 0; i < 2; i++) {
95                 extension = calloc(1, sizeof(struct extension));
96                 snprintf(extension->overlay, sizeof(extension->overlay), "overlay%d.dtbo", i);
97                 snprintf(extension->name, sizeof(extension->name), "extension board %d", i);
98                 snprintf(extension->owner, sizeof(extension->owner), "sandbox");
99                 snprintf(extension->version, sizeof(extension->version), "1.1");
100                 snprintf(extension->other, sizeof(extension->other), "Fictionnal extension board");
101                 list_add_tail(&extension->list, extension_list);
102         }
103
104         return i;
105 }
106 #endif
107
108 #ifdef CONFIG_BOARD_LATE_INIT
109 int board_late_init(void)
110 {
111         struct udevice *dev;
112         int ret;
113
114         ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
115         if (ret && ret != -ENODEV) {
116                 /* Force console on */
117                 gd->flags &= ~GD_FLG_SILENT;
118
119                 printf("cros-ec communications failure %d\n", ret);
120                 puts("\nPlease reset with Power+Refresh\n\n");
121                 panic("Cannot init cros-ec device");
122                 return -1;
123         }
124         return 0;
125 }
126 #endif