Duje Mihanović | ba441f5 | 2025-01-24 16:47:49 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (c) 2024 |
| 4 | * Duje Mihanović <duje.mihanovic@skole.hr> |
| 5 | */ |
| 6 | #include <errno.h> |
| 7 | #include <init.h> |
| 8 | #include <fdt_support.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/global_data.h> |
| 11 | |
| 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
| 14 | /* Timer constants */ |
| 15 | #define APBC_COUNTER_CLK_SEL 0xd4015064 |
| 16 | #define COUNTER_BASE 0xd4101000 |
| 17 | #define COUNTER_EN BIT(0) |
| 18 | #define COUNTER_HALT_ON_DEBUG BIT(1) |
| 19 | |
| 20 | int timer_init(void) |
| 21 | { |
| 22 | u32 tmp = readl(APBC_COUNTER_CLK_SEL); |
| 23 | |
| 24 | if ((tmp >> 16) != 0x319) |
| 25 | return -1; |
| 26 | |
| 27 | /* Set timer frequency to 26MHz */ |
| 28 | writel(tmp | 1, APBC_COUNTER_CLK_SEL); |
| 29 | writel(COUNTER_EN | COUNTER_HALT_ON_DEBUG, COUNTER_BASE); |
| 30 | |
| 31 | gd->arch.timer_rate_hz = 26000000; |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | int board_init(void) |
| 37 | { |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | int dram_init(void) |
| 42 | { |
| 43 | if (fdtdec_setup_mem_size_base() != 0) |
| 44 | puts("fdtdec_setup_mem_size_base() has failed\n"); |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | #ifndef CONFIG_SYSRESET |
| 50 | void reset_cpu(void) |
| 51 | { |
| 52 | } |
| 53 | #endif |
| 54 | |
| 55 | /* Stolen from arch/arm/mach-snapdragon/board.c */ |
| 56 | int board_fdt_blob_setup(void **fdtp) |
| 57 | { |
| 58 | struct fdt_header *fdt; |
| 59 | bool internal_valid, external_valid; |
| 60 | int ret = 0; |
| 61 | |
| 62 | fdt = (struct fdt_header *)get_prev_bl_fdt_addr(); |
| 63 | external_valid = fdt && !fdt_check_header(fdt); |
| 64 | internal_valid = !fdt_check_header(*fdtp); |
| 65 | |
| 66 | /* |
| 67 | * There is no point returning an error here, U-Boot can't do anything useful in this situation. |
| 68 | * Bail out while we can still print a useful error message. |
| 69 | */ |
| 70 | if (!internal_valid && !external_valid) |
| 71 | panic("Internal FDT is invalid and no external FDT was provided! (fdt=%#llx)\n", |
| 72 | (phys_addr_t)fdt); |
| 73 | |
| 74 | if (internal_valid) { |
| 75 | debug("Using built in FDT\n"); |
| 76 | ret = -EEXIST; |
| 77 | } else { |
| 78 | debug("Using external FDT\n"); |
| 79 | /* So we can use it before returning */ |
| 80 | *fdtp = fdt; |
| 81 | } |
| 82 | |
| 83 | return ret; |
| 84 | } |