blob: 5d9a945d64c0d27e7feffbbe250f2c1a2ae5ae2a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassf1a6c762011-10-07 13:53:38 +00002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glassf1a6c762011-10-07 13:53:38 +00004 */
5
6#include <common.h>
Simon Glass63334482019-11-14 12:57:39 -07007#include <cpu_func.h>
Simon Glassfd173402014-02-27 13:26:13 -07008#include <cros_ec.h>
Simon Glassb4d70702014-02-26 15:59:25 -07009#include <dm.h>
Patrick Delaunayd34a6a22020-07-28 11:51:22 +020010#include <env_internal.h>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Patrick Delaunay29bf6032018-07-27 16:37:09 +020012#include <led.h>
Matthias Weisser0d3dd142011-11-29 12:16:40 +010013#include <os.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Joe Hershberger74961352015-04-21 13:57:18 -050015#include <asm/test.h>
Simon Glassb9ddbf42014-02-27 13:26:19 -070016#include <asm/u-boot-sandbox.h>
Kory Maincent965a34f2021-05-04 19:31:23 +020017#include <malloc.h>
18
19#include <extension_board.h>
Matthias Weisser0d3dd142011-11-29 12:16:40 +010020
Simon Glassf1a6c762011-10-07 13:53:38 +000021/*
22 * Pointer to initial global data area
23 *
24 * Here we initialize it.
25 */
26gd_t *gd;
27
Simon Glasscb90bd32020-10-03 11:31:23 -060028#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glass92882652021-08-07 07:24:04 -060029/*
30 * Add a simple GPIO device (don't use with of-platdata as it interferes with
31 * the auto-generated devices)
32 */
Simon Glass1d8364a2020-12-28 20:34:54 -070033U_BOOT_DRVINFO(gpio_sandbox) = {
Walter Lozano2901ac62020-06-25 01:10:04 -030034 .name = "sandbox_gpio",
Simon Glassb4d70702014-02-26 15:59:25 -070035};
Simon Glasscb90bd32020-10-03 11:31:23 -060036#endif
Simon Glassb4d70702014-02-26 15:59:25 -070037
Thomas Chou7b059dc2015-10-30 15:35:52 +080038#ifndef CONFIG_TIMER
Joe Hershberger74961352015-04-21 13:57:18 -050039/* system timer offset in ms */
40static unsigned long sandbox_timer_offset;
41
Neil Armstrong77c0dbc2019-04-11 17:01:23 +020042void timer_test_add_offset(unsigned long offset)
Joe Hershberger74961352015-04-21 13:57:18 -050043{
44 sandbox_timer_offset += offset;
45}
46
Rob Herring86bd4e82013-11-08 08:40:44 -060047unsigned long timer_read_counter(void)
Simon Glassf1a6c762011-10-07 13:53:38 +000048{
Joe Hershberger74961352015-04-21 13:57:18 -050049 return os_get_nsec() / 1000 + sandbox_timer_offset * 1000;
Simon Glassf1a6c762011-10-07 13:53:38 +000050}
Thomas Chou7b059dc2015-10-30 15:35:52 +080051#endif
Simon Glassf1a6c762011-10-07 13:53:38 +000052
Patrick Delaunayd34a6a22020-07-28 11:51:22 +020053/* specific order for sandbox: nowhere is the first value, used by default */
54static enum env_location env_locations[] = {
55 ENVL_NOWHERE,
56 ENVL_EXT4,
Heinrich Schuchardt55cbdf82021-03-04 18:28:37 +000057 ENVL_FAT,
Patrick Delaunayd34a6a22020-07-28 11:51:22 +020058};
59
60enum 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
Simon Glassf1a6c762011-10-07 13:53:38 +000068int dram_init(void)
69{
Simon Glass62cf9122013-04-26 02:53:43 +000070 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
Simon Glassf1a6c762011-10-07 13:53:38 +000071 return 0;
72}
Simon Glassfd173402014-02-27 13:26:13 -070073
Patrick Delaunay29bf6032018-07-27 16:37:09 +020074int board_init(void)
75{
76 if (IS_ENABLED(CONFIG_LED))
77 led_default_state();
78
79 return 0;
80}
81
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090082int ft_board_setup(void *fdt, struct bd_info *bd)
Heinrich Schuchardta3fc9a42020-03-14 12:13:40 +010083{
84 /* Create an arbitrary reservation to allow testing OF_BOARD_SETUP.*/
85 return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
86}
87
Kory Maincent965a34f2021-05-04 19:31:23 +020088#ifdef CONFIG_CMD_EXTENSION
89int 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
Simon Glassfd173402014-02-27 13:26:13 -0700108#ifdef CONFIG_BOARD_LATE_INIT
109int board_late_init(void)
110{
Simon Glassfe3f6432018-11-06 15:21:26 -0700111 struct udevice *dev;
112 int ret;
113
114 ret = uclass_first_device_err(UCLASS_CROS_EC, &dev);
115 if (ret && ret != -ENODEV) {
Simon Glassfd173402014-02-27 13:26:13 -0700116 /* Force console on */
117 gd->flags &= ~GD_FLG_SILENT;
118
Simon Glassfe3f6432018-11-06 15:21:26 -0700119 printf("cros-ec communications failure %d\n", ret);
Simon Glassfd173402014-02-27 13:26:13 -0700120 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