Bin Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com> |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Bin Meng | 3c5196d | 2018-10-15 02:21:13 -0700 | [diff] [blame] | 7 | #include <dm.h> |
Anup Patel | ef19131 | 2022-01-27 11:41:09 +0530 | [diff] [blame] | 8 | #include <dm/ofnode.h> |
Simon Glass | c7694dd | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 9 | #include <env.h> |
Bin Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 10 | #include <fdtdec.h> |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 11 | #include <image.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Lukas Auer | e456a81 | 2019-08-21 21:14:49 +0200 | [diff] [blame] | 13 | #include <spl.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 14 | #include <init.h> |
Bin Meng | 02be57c | 2023-07-23 12:40:41 +0800 | [diff] [blame] | 15 | #include <usb.h> |
Bin Meng | 3c5196d | 2018-10-15 02:21:13 -0700 | [diff] [blame] | 16 | #include <virtio_types.h> |
| 17 | #include <virtio.h> |
Bin Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 18 | |
Ilias Apalodimas | 2e8d2f8 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Anup Patel | ef19131 | 2022-01-27 11:41:09 +0530 | [diff] [blame] | 21 | #if IS_ENABLED(CONFIG_MTD_NOR_FLASH) |
| 22 | int 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 Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 32 | int board_init(void) |
| 33 | { |
Bin Meng | 3c5196d | 2018-10-15 02:21:13 -0700 | [diff] [blame] | 34 | /* |
| 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 Meng | 510e379 | 2018-09-26 06:55:21 -0700 | [diff] [blame] | 40 | return 0; |
| 41 | } |
Lukas Auer | 66ffe57 | 2018-11-22 11:26:36 +0100 | [diff] [blame] | 42 | |
| 43 | int board_late_init(void) |
| 44 | { |
Bin Meng | 02be57c | 2023-07-23 12:40:41 +0800 | [diff] [blame] | 45 | /* start usb so that usb keyboard can be used as input device */ |
| 46 | if (CONFIG_IS_ENABLED(USB_KEYBOARD)) |
| 47 | usb_init(); |
| 48 | |
Lukas Auer | 66ffe57 | 2018-11-22 11:26:36 +0100 | [diff] [blame] | 49 | return 0; |
| 50 | } |
Lukas Auer | 897206c | 2018-11-22 11:26:37 +0100 | [diff] [blame] | 51 | |
Lukas Auer | e456a81 | 2019-08-21 21:14:49 +0200 | [diff] [blame] | 52 | #ifdef CONFIG_SPL |
| 53 | u32 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 |
| 61 | int board_fit_config_name_match(const char *name) |
| 62 | { |
| 63 | /* boot using first FIT config */ |
| 64 | return 0; |
| 65 | } |
| 66 | #endif |
Ilias Apalodimas | 2e8d2f8 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 67 | |
Ilias Apalodimas | e7fb789 | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 68 | void *board_fdt_blob_setup(int *err) |
Ilias Apalodimas | 2e8d2f8 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 69 | { |
Ilias Apalodimas | e7fb789 | 2021-10-26 09:12:33 +0300 | [diff] [blame] | 70 | *err = 0; |
Ilias Apalodimas | 2e8d2f8 | 2021-10-12 00:00:13 +0300 | [diff] [blame] | 71 | /* Stored the DTB address there during our init */ |
| 72 | return (void *)(ulong)gd->arch.firmware_fdt_addr; |
| 73 | } |