blob: 181abbbf97d845da2eba212f1039f4ff3c2c3f3c [file] [log] [blame]
Bin Meng510e3792018-09-26 06:55:21 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
4 */
5
6#include <common.h>
Bin Meng3c5196d2018-10-15 02:21:13 -07007#include <dm.h>
Anup Patelef191312022-01-27 11:41:09 +05308#include <dm/ofnode.h>
Simon Glassc7694dd2019-08-01 09:46:46 -06009#include <env.h>
Bin Meng510e3792018-09-26 06:55:21 -070010#include <fdtdec.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060011#include <image.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060012#include <log.h>
Lukas Auere456a812019-08-21 21:14:49 +020013#include <spl.h>
Simon Glass52559322019-11-14 12:57:46 -070014#include <init.h>
Bin Meng02be57c2023-07-23 12:40:41 +080015#include <usb.h>
Bin Meng3c5196d2018-10-15 02:21:13 -070016#include <virtio_types.h>
17#include <virtio.h>
Bin Meng510e3792018-09-26 06:55:21 -070018
Ilias Apalodimas2e8d2f82021-10-12 00:00:13 +030019DECLARE_GLOBAL_DATA_PTR;
20
Anup Patelef191312022-01-27 11:41:09 +053021#if IS_ENABLED(CONFIG_MTD_NOR_FLASH)
22int is_flash_available(void)
23{
24 if (!ofnode_equal(ofnode_by_compatible(ofnode_null(), "cfi-flash"),
25 ofnode_null()))
26 return 1;
27
28 return 0;
29}
30#endif
31
Bin Meng510e3792018-09-26 06:55:21 -070032int board_init(void)
33{
Bin Meng3c5196d2018-10-15 02:21:13 -070034 /*
35 * Make sure virtio bus is enumerated so that peripherals
36 * on the virtio bus can be discovered by their drivers
37 */
38 virtio_init();
39
Bin Meng510e3792018-09-26 06:55:21 -070040 return 0;
41}
Lukas Auer66ffe572018-11-22 11:26:36 +010042
43int board_late_init(void)
44{
Bin Meng02be57c2023-07-23 12:40:41 +080045 /* start usb so that usb keyboard can be used as input device */
46 if (CONFIG_IS_ENABLED(USB_KEYBOARD))
47 usb_init();
48
Lukas Auer66ffe572018-11-22 11:26:36 +010049 return 0;
50}
Lukas Auer897206c2018-11-22 11:26:37 +010051
Lukas Auere456a812019-08-21 21:14:49 +020052#ifdef CONFIG_SPL
53u32 spl_boot_device(void)
54{
55 /* RISC-V QEMU only supports RAM as SPL boot device */
56 return BOOT_DEVICE_RAM;
57}
58#endif
59
60#ifdef CONFIG_SPL_LOAD_FIT
61int board_fit_config_name_match(const char *name)
62{
63 /* boot using first FIT config */
64 return 0;
65}
66#endif
Ilias Apalodimas2e8d2f82021-10-12 00:00:13 +030067
Ilias Apalodimase7fb7892021-10-26 09:12:33 +030068void *board_fdt_blob_setup(int *err)
Ilias Apalodimas2e8d2f82021-10-12 00:00:13 +030069{
Ilias Apalodimase7fb7892021-10-26 09:12:33 +030070 *err = 0;
Ilias Apalodimas2e8d2f82021-10-12 00:00:13 +030071 /* Stored the DTB address there during our init */
72 return (void *)(ulong)gd->arch.firmware_fdt_addr;
73}