blob: e4217c8a2c77de25c33d5a102e903b78dffa3ccf [file] [log] [blame]
wdenk5c952cf2004-10-10 21:27:30 +00001/*
2 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
3 * Scott McNutt <smcnutt@psyent.com>
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk5c952cf2004-10-10 21:27:30 +00006 */
7
8#include <common.h>
Thomas Choubcae80e2015-10-21 21:34:57 +08009#include <cpu.h>
10#include <dm.h>
11#include <errno.h>
Joachim Foersterf956ad92011-10-20 10:28:10 +020012#include <asm/cache.h>
wdenk5c952cf2004-10-10 21:27:30 +000013
Thomas Chou5ff10aa2014-08-22 11:36:47 +080014DECLARE_GLOBAL_DATA_PTR;
15
Thomas Chou5ff10aa2014-08-22 11:36:47 +080016#ifdef CONFIG_DISPLAY_CPUINFO
17int print_cpuinfo(void)
wdenk5c952cf2004-10-10 21:27:30 +000018{
Thomas Chouca844dd2015-10-14 08:43:31 +080019 printf("CPU: Nios-II\n");
20 return 0;
wdenk5c952cf2004-10-10 21:27:30 +000021}
Thomas Chou5ff10aa2014-08-22 11:36:47 +080022#endif /* CONFIG_DISPLAY_CPUINFO */
wdenk5c952cf2004-10-10 21:27:30 +000023
Mike Frysinger882b7d72010-10-20 03:41:17 -040024int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk5c952cf2004-10-10 21:27:30 +000025{
Thomas Chou7a6a7d12010-08-16 10:49:44 +080026 disable_interrupts();
27 /* indirect call to go beyond 256MB limitation of toolchain */
Thomas Chou121e36d2015-10-09 09:43:52 +080028 nios2_callr(gd->arch.reset_addr);
Thomas Chou7a6a7d12010-08-16 10:49:44 +080029 return 0;
wdenk5c952cf2004-10-10 21:27:30 +000030}
Joachim Foersterf956ad92011-10-20 10:28:10 +020031
Thomas Choubcae80e2015-10-21 21:34:57 +080032int arch_cpu_init_dm(void)
Thomas Chou5ff10aa2014-08-22 11:36:47 +080033{
Thomas Choubcae80e2015-10-21 21:34:57 +080034 struct udevice *dev;
35 int ret;
36
37 ret = uclass_first_device(UCLASS_CPU, &dev);
38 if (ret)
39 return ret;
40 if (!dev)
41 return -ENODEV;
42
Thomas Chou5ff10aa2014-08-22 11:36:47 +080043 gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
44
45 return 0;
46}
Thomas Choubcae80e2015-10-21 21:34:57 +080047
48static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size)
49{
50 const char *cpu_name = "Nios-II";
51
52 if (size < strlen(cpu_name))
53 return -ENOSPC;
54 strcpy(buf, cpu_name);
55
56 return 0;
57}
58
59static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info)
60{
61 info->cpu_freq = gd->cpu_clk;
62 info->features = (1 << CPU_FEAT_L1_CACHE) |
63 (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0);
64
65 return 0;
66}
67
68static int altera_nios2_get_count(struct udevice *dev)
69{
70 return 1;
71}
72
73static int altera_nios2_probe(struct udevice *dev)
74{
75 const void *blob = gd->fdt_blob;
76 int node = dev->of_offset;
77
78 gd->cpu_clk = fdtdec_get_int(blob, node,
79 "clock-frequency", 0);
80 gd->arch.dcache_line_size = fdtdec_get_int(blob, node,
81 "dcache-line-size", 0);
82 gd->arch.icache_line_size = fdtdec_get_int(blob, node,
83 "icache-line-size", 0);
84 gd->arch.dcache_size = fdtdec_get_int(blob, node,
85 "dcache-size", 0);
86 gd->arch.icache_size = fdtdec_get_int(blob, node,
87 "icache-size", 0);
88 gd->arch.reset_addr = fdtdec_get_int(blob, node,
89 "altr,reset-addr", 0);
90 gd->arch.exception_addr = fdtdec_get_int(blob, node,
91 "altr,exception-addr", 0);
92 gd->arch.has_initda = fdtdec_get_int(blob, node,
93 "altr,has-initda", 0);
94 gd->arch.has_mmu = fdtdec_get_int(blob, node,
95 "altr,has-mmu", 0);
96 gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x8000000;
97
98 return 0;
99}
100
101static const struct cpu_ops altera_nios2_ops = {
102 .get_desc = altera_nios2_get_desc,
103 .get_info = altera_nios2_get_info,
104 .get_count = altera_nios2_get_count,
105};
106
107static const struct udevice_id altera_nios2_ids[] = {
108 { .compatible = "altr,nios2-1.0" },
109 { .compatible = "altr,nios2-1.1" },
110 { }
111};
112
113U_BOOT_DRIVER(altera_nios2) = {
114 .name = "altera_nios2",
115 .id = UCLASS_CPU,
116 .of_match = altera_nios2_ids,
117 .probe = altera_nios2_probe,
118 .ops = &altera_nios2_ops,
119 .flags = DM_FLAG_PRE_RELOC,
120};