2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2004-10-10 21:27:30 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2004, Psyent Corporation <www.psyent.com>
|
|
|
|
* Scott McNutt <smcnutt@psyent.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:03 +00:00
|
|
|
#include <command.h>
|
2015-10-21 13:34:57 +00:00
|
|
|
#include <cpu.h>
|
2019-11-14 19:57:39 +00:00
|
|
|
#include <cpu_func.h>
|
2015-10-21 13:34:57 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
2022-03-04 15:43:05 +00:00
|
|
|
#include <event.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2019-11-14 19:57:42 +00:00
|
|
|
#include <irq_func.h>
|
2011-10-20 08:28:10 +00:00
|
|
|
#include <asm/cache.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <asm/system.h>
|
2004-10-10 21:27:30 +00:00
|
|
|
|
2014-08-22 03:36:47 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
#ifdef CONFIG_DISPLAY_CPUINFO
|
|
|
|
int print_cpuinfo(void)
|
2004-10-10 21:27:30 +00:00
|
|
|
{
|
2015-10-14 00:43:31 +00:00
|
|
|
printf("CPU: Nios-II\n");
|
|
|
|
return 0;
|
2004-10-10 21:27:30 +00:00
|
|
|
}
|
2014-08-22 03:36:47 +00:00
|
|
|
#endif /* CONFIG_DISPLAY_CPUINFO */
|
2004-10-10 21:27:30 +00:00
|
|
|
|
2015-12-16 08:07:06 +00:00
|
|
|
#ifdef CONFIG_ALTERA_SYSID
|
|
|
|
int checkboard(void)
|
|
|
|
{
|
|
|
|
display_sysid();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
|
2004-10-10 21:27:30 +00:00
|
|
|
{
|
2010-08-16 02:49:44 +00:00
|
|
|
disable_interrupts();
|
|
|
|
/* indirect call to go beyond 256MB limitation of toolchain */
|
2015-10-09 01:43:52 +00:00
|
|
|
nios2_callr(gd->arch.reset_addr);
|
2010-08-16 02:49:44 +00:00
|
|
|
return 0;
|
2004-10-10 21:27:30 +00:00
|
|
|
}
|
2011-10-20 08:28:10 +00:00
|
|
|
|
2015-10-06 06:09:19 +00:00
|
|
|
/*
|
|
|
|
* COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
|
|
|
|
* exception address. Define CONFIG_ROM_STUBS to prevent
|
|
|
|
* the copy (e.g. exception in flash or in other
|
|
|
|
* softare/firmware component).
|
|
|
|
*/
|
|
|
|
#ifndef CONFIG_ROM_STUBS
|
|
|
|
static void copy_exception_trampoline(void)
|
|
|
|
{
|
|
|
|
extern int _except_start, _except_end;
|
|
|
|
void *except_target = (void *)gd->arch.exception_addr;
|
|
|
|
|
|
|
|
if (&_except_start != except_target) {
|
|
|
|
memcpy(except_target, &_except_start,
|
|
|
|
&_except_end - &_except_start);
|
|
|
|
flush_cache(gd->arch.exception_addr,
|
|
|
|
&_except_end - &_except_start);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-03-04 15:43:05 +00:00
|
|
|
static int nios_cpu_setup(void *ctx, struct event *event)
|
2014-08-22 03:36:47 +00:00
|
|
|
{
|
2015-10-21 13:34:57 +00:00
|
|
|
struct udevice *dev;
|
|
|
|
int ret;
|
|
|
|
|
2016-02-11 20:23:26 +00:00
|
|
|
ret = uclass_first_device_err(UCLASS_CPU, &dev);
|
2015-10-21 13:34:57 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2022-11-16 18:10:37 +00:00
|
|
|
gd->ram_size = CFG_SYS_SDRAM_SIZE;
|
2015-10-06 06:09:19 +00:00
|
|
|
#ifndef CONFIG_ROM_STUBS
|
|
|
|
copy_exception_trampoline();
|
|
|
|
#endif
|
2014-08-22 03:36:47 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2022-03-04 15:43:05 +00:00
|
|
|
EVENT_SPY(EVT_DM_POST_INIT, nios_cpu_setup);
|
2015-10-21 13:34:57 +00:00
|
|
|
|
2020-01-27 05:06:27 +00:00
|
|
|
static int altera_nios2_get_desc(const struct udevice *dev, char *buf,
|
|
|
|
int size)
|
2015-10-21 13:34:57 +00:00
|
|
|
{
|
|
|
|
const char *cpu_name = "Nios-II";
|
|
|
|
|
|
|
|
if (size < strlen(cpu_name))
|
|
|
|
return -ENOSPC;
|
|
|
|
strcpy(buf, cpu_name);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-27 05:06:27 +00:00
|
|
|
static int altera_nios2_get_info(const struct udevice *dev,
|
|
|
|
struct cpu_info *info)
|
2015-10-21 13:34:57 +00:00
|
|
|
{
|
|
|
|
info->cpu_freq = gd->cpu_clk;
|
|
|
|
info->features = (1 << CPU_FEAT_L1_CACHE) |
|
|
|
|
(gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-27 05:06:27 +00:00
|
|
|
static int altera_nios2_get_count(const struct udevice *dev)
|
2015-10-21 13:34:57 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int altera_nios2_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
const void *blob = gd->fdt_blob;
|
2017-01-17 23:52:55 +00:00
|
|
|
int node = dev_of_offset(dev);
|
2015-10-21 13:34:57 +00:00
|
|
|
|
|
|
|
gd->cpu_clk = fdtdec_get_int(blob, node,
|
|
|
|
"clock-frequency", 0);
|
|
|
|
gd->arch.dcache_line_size = fdtdec_get_int(blob, node,
|
|
|
|
"dcache-line-size", 0);
|
|
|
|
gd->arch.icache_line_size = fdtdec_get_int(blob, node,
|
|
|
|
"icache-line-size", 0);
|
|
|
|
gd->arch.dcache_size = fdtdec_get_int(blob, node,
|
|
|
|
"dcache-size", 0);
|
|
|
|
gd->arch.icache_size = fdtdec_get_int(blob, node,
|
|
|
|
"icache-size", 0);
|
|
|
|
gd->arch.reset_addr = fdtdec_get_int(blob, node,
|
|
|
|
"altr,reset-addr", 0);
|
|
|
|
gd->arch.exception_addr = fdtdec_get_int(blob, node,
|
|
|
|
"altr,exception-addr", 0);
|
|
|
|
gd->arch.has_initda = fdtdec_get_int(blob, node,
|
|
|
|
"altr,has-initda", 0);
|
|
|
|
gd->arch.has_mmu = fdtdec_get_int(blob, node,
|
|
|
|
"altr,has-mmu", 0);
|
2015-10-27 00:30:22 +00:00
|
|
|
gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x80000000;
|
|
|
|
gd->arch.mem_region_base = gd->arch.has_mmu ? 0xc0000000 : 0x00000000;
|
2015-10-27 01:02:17 +00:00
|
|
|
gd->arch.physaddr_mask = gd->arch.has_mmu ? 0x1fffffff : 0x7fffffff;
|
2015-10-21 13:34:57 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct cpu_ops altera_nios2_ops = {
|
|
|
|
.get_desc = altera_nios2_get_desc,
|
|
|
|
.get_info = altera_nios2_get_info,
|
|
|
|
.get_count = altera_nios2_get_count,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id altera_nios2_ids[] = {
|
|
|
|
{ .compatible = "altr,nios2-1.0" },
|
|
|
|
{ .compatible = "altr,nios2-1.1" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(altera_nios2) = {
|
|
|
|
.name = "altera_nios2",
|
|
|
|
.id = UCLASS_CPU,
|
|
|
|
.of_match = altera_nios2_ids,
|
|
|
|
.probe = altera_nios2_probe,
|
|
|
|
.ops = &altera_nios2_ops,
|
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
|
|
|
};
|
2017-04-06 18:47:05 +00:00
|
|
|
|
|
|
|
/* This is a dummy function on nios2 */
|
|
|
|
int dram_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|