Files
opensbi/platform/generic/sophgo/sg2042.c
chunzhi.lin 9a53bd85c5 SOPHGO: SG2042: Fix up timer init error
Timer init failed with the following error message in Pisces. Add 16 timers memrange(the default number) in sg2042_early_init while Pisces pruduct has 32 timers.

sbi_domain_root_add_memrange: line 678, 0x70ac1b4000,0x1000,0x80000003
sbi_domain_root_add_memrange: line 678, 0x70ac1b5000,0x1000,0x80000003
sbi_domain_root_add_memrange: line 678, 0x70ac1b6000,0x1000,0x80000003
sbi_domain_root_add_memrange: line 678, 0x70ac1b7000,0x1000,0x80000003
sbi_domain_root_add_memrange: line 678, 0x70ac1b8000,0x1000,0x80000003
sbi_domain_root_add_memrange: line 678, 0x70ac1b9000,0x1000,0x80000003
sbi_domain_root_add_memrange: line 678, 0x70ac1ba000,0x1000,0x80000003
sbi_domain_root_add_memrange: line 678, 0x70ac1bb000,0x1000,0x80000003
fdt_driver_init_by_offset: timer@70ac1b4000 (thead,c900-aclint-mtimer) init failed: -3
init_coldboot: timer init failed (error -3)

Signed-off-by: chunzhi.lin <chunzhi.lin@sophgo.com>
2025-07-21 11:16:14 +08:00

81 lines
1.8 KiB
C

/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Authors:
* Inochi Amaoto <inochiama@outlook.com>
*
*/
#include <platform_override.h>
#include <thead/c9xx_errata.h>
#include <thead/c9xx_pmu.h>
#include <sbi/sbi_const.h>
#include <sbi/sbi_domain.h>
#include <sbi/sbi_platform.h>
#include <sbi/sbi_scratch.h>
#include <sbi/sbi_string.h>
#include <sbi_utils/fdt/fdt_helper.h>
#include <sbi_utils/timer/aclint_mtimer.h>
#define SOPHGO_SG2042_TIMER_BASE 0x70ac000000ULL
#define SOPHGO_SG2042_TIMER_SIZE 0x10000UL
#define SOPHGO_SG2042_TIMER_NUM 32
static int sophgo_sg2042_early_init(bool cold_boot)
{
int rc;
rc = generic_early_init(cold_boot);
if (rc)
return rc;
thead_register_tlb_flush_trap_handler();
/*
* Sophgo sg2042 soc use separate 16/32 timers while initiating,
* merge them as a single domain to avoid wasting.
*/
if (cold_boot)
return sbi_domain_root_add_memrange(
(ulong)SOPHGO_SG2042_TIMER_BASE,
SOPHGO_SG2042_TIMER_SIZE *
SOPHGO_SG2042_TIMER_NUM,
MTIMER_REGION_ALIGN,
(SBI_DOMAIN_MEMREGION_MMIO |
SBI_DOMAIN_MEMREGION_M_READABLE |
SBI_DOMAIN_MEMREGION_M_WRITABLE));
return 0;
}
static int sophgo_sg2042_extensions_init(struct sbi_hart_features *hfeatures)
{
int rc;
rc = generic_extensions_init(hfeatures);
if (rc)
return rc;
thead_c9xx_register_pmu_device();
return 0;
}
static int sophgo_sg2042_platform_init(const void *fdt, int nodeoff, const struct fdt_match *match)
{
generic_platform_ops.early_init = sophgo_sg2042_early_init;
generic_platform_ops.extensions_init = sophgo_sg2042_extensions_init;
return 0;
}
static const struct fdt_match sophgo_sg2042_match[] = {
{ .compatible = "sophgo,sg2042" },
{ },
};
const struct fdt_driver sophgo_sg2042 = {
.match_table = sophgo_sg2042_match,
.init = sophgo_sg2042_platform_init,
};