Adjust the existing hooks to use a driver instead.

Signed-off-by: Simon Glass <s...@chromium.org>
---

 arch/Kconfig            |  3 +++
 board/sandbox/sandbox.c | 44 ++++++++++++++++++++++++++++++++++++++------
 2 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/arch/Kconfig b/arch/Kconfig
index 76c690f667..f07070db18 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -64,6 +64,9 @@ config SANDBOX
        bool "Sandbox"
        select BOARD_LATE_INIT
        select SUPPORT_OF_CONTROL
+       select BOARD
+       select SPL_BOARD
+       select BOARD_ENABLE
        select DM
        select DM_KEYBOARD
        select DM_SPI_FLASH
diff --git a/board/sandbox/sandbox.c b/board/sandbox/sandbox.c
index b41e9decb3..1eea20cbcb 100644
--- a/board/sandbox/sandbox.c
+++ b/board/sandbox/sandbox.c
@@ -7,6 +7,7 @@
 #include <cros_ec.h>
 #include <dm.h>
 #include <os.h>
+#include <asm/state.h>
 #include <asm/test.h>
 #include <asm/u-boot-sandbox.h>
 
@@ -41,12 +42,6 @@ unsigned long timer_read_counter(void)
 }
 #endif
 
-int dram_init(void)
-{
-       gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
-       return 0;
-}
-
 #ifdef CONFIG_BOARD_LATE_INIT
 int board_late_init(void)
 {
@@ -63,3 +58,40 @@ int board_late_init(void)
        return 0;
 }
 #endif
+
+static int sandbox_phase(struct udevice *dev, enum board_phase_t phase)
+{
+       struct sandbox_state *state = state_get_current();
+
+       switch (phase) {
+       case BOARD_F_DRAM_INIT:
+               gd->ram_size = state->ram_size;
+               return 0;
+       default:
+               return -ENOSYS;
+       }
+
+       return 0;
+}
+
+static int sandbox_board_probe(struct udevice *dev)
+{
+       return board_support_phase(dev, BOARD_F_DRAM_INIT);
+}
+
+static const struct board_ops sandbox_board_ops = {
+       .phase          = sandbox_phase,
+};
+
+/* Name this starting with underscore so it will be called last */
+U_BOOT_DRIVER(_sandbox_board_drv) = {
+       .name           = "sandbox_board",
+       .id             = UCLASS_BOARD,
+       .ops            = &sandbox_board_ops,
+       .probe          = sandbox_board_probe,
+       .flags          = DM_FLAG_PRE_RELOC,
+};
+
+U_BOOT_DEVICE(sandbox_board) = {
+       .name           = "sandbox_board",
+};
-- 
2.12.0.367.g23dc2f6d3c-goog

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to