xref: /rk3399_rockchip-uboot/arch/nios2/cpu/cpu.c (revision 121e36dacdfa0ef68414effea4d758e8fc2f3b60)
137e4dafaSPeter Tyser /*
237e4dafaSPeter Tyser  * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
337e4dafaSPeter Tyser  * Scott McNutt <smcnutt@psyent.com>
437e4dafaSPeter Tyser  *
51a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
637e4dafaSPeter Tyser  */
737e4dafaSPeter Tyser 
837e4dafaSPeter Tyser #include <common.h>
9bcae80e9SThomas Chou #include <cpu.h>
10bcae80e9SThomas Chou #include <dm.h>
11bcae80e9SThomas Chou #include <errno.h>
12f956ad98SJoachim Foerster #include <asm/cache.h>
1337e4dafaSPeter Tyser 
145ff10aa7SThomas Chou DECLARE_GLOBAL_DATA_PTR;
155ff10aa7SThomas Chou 
165ff10aa7SThomas Chou #ifdef CONFIG_DISPLAY_CPUINFO
175ff10aa7SThomas Chou int print_cpuinfo(void)
1837e4dafaSPeter Tyser {
1937e4dafaSPeter Tyser 	printf("CPU:   Nios-II\n");
20ca844dd8SThomas Chou 	return 0;
2137e4dafaSPeter Tyser }
225ff10aa7SThomas Chou #endif /* CONFIG_DISPLAY_CPUINFO */
2337e4dafaSPeter Tyser 
24882b7d72SMike Frysinger int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
2537e4dafaSPeter Tyser {
2637e4dafaSPeter Tyser 	disable_interrupts();
277a6a7d10SThomas Chou 	/* indirect call to go beyond 256MB limitation of toolchain */
28*121e36daSThomas Chou 	nios2_callr(gd->arch.reset_addr);
297a6a7d10SThomas Chou 	return 0;
3037e4dafaSPeter Tyser }
31f956ad98SJoachim Foerster 
32f956ad98SJoachim Foerster int dcache_status(void)
33f956ad98SJoachim Foerster {
34f956ad98SJoachim Foerster 	return 1;
35f956ad98SJoachim Foerster }
36f956ad98SJoachim Foerster 
37f956ad98SJoachim Foerster void dcache_enable(void)
38f956ad98SJoachim Foerster {
39f956ad98SJoachim Foerster 	flush_dcache(CONFIG_SYS_DCACHE_SIZE, CONFIG_SYS_DCACHELINE_SIZE);
40f956ad98SJoachim Foerster }
41f956ad98SJoachim Foerster 
42f956ad98SJoachim Foerster void dcache_disable(void)
43f956ad98SJoachim Foerster {
44f956ad98SJoachim Foerster 	flush_dcache(CONFIG_SYS_DCACHE_SIZE, CONFIG_SYS_DCACHELINE_SIZE);
45f956ad98SJoachim Foerster }
465ff10aa7SThomas Chou 
47bcae80e9SThomas Chou int arch_cpu_init_dm(void)
485ff10aa7SThomas Chou {
49bcae80e9SThomas Chou 	struct udevice *dev;
50bcae80e9SThomas Chou 	int ret;
51bcae80e9SThomas Chou 
52bcae80e9SThomas Chou 	ret = uclass_first_device(UCLASS_CPU, &dev);
53bcae80e9SThomas Chou 	if (ret)
54bcae80e9SThomas Chou 		return ret;
55bcae80e9SThomas Chou 	if (!dev)
56bcae80e9SThomas Chou 		return -ENODEV;
57bcae80e9SThomas Chou 
585ff10aa7SThomas Chou 	gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
595ff10aa7SThomas Chou 
605ff10aa7SThomas Chou 	return 0;
615ff10aa7SThomas Chou }
62bcae80e9SThomas Chou 
63bcae80e9SThomas Chou static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size)
64bcae80e9SThomas Chou {
65bcae80e9SThomas Chou 	const char *cpu_name = "Nios-II";
66bcae80e9SThomas Chou 
67bcae80e9SThomas Chou 	if (size < strlen(cpu_name))
68bcae80e9SThomas Chou 		return -ENOSPC;
69bcae80e9SThomas Chou 	strcpy(buf, cpu_name);
70bcae80e9SThomas Chou 
71bcae80e9SThomas Chou 	return 0;
72bcae80e9SThomas Chou }
73bcae80e9SThomas Chou 
74bcae80e9SThomas Chou static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info)
75bcae80e9SThomas Chou {
76bcae80e9SThomas Chou 	info->cpu_freq = gd->cpu_clk;
77bcae80e9SThomas Chou 	info->features = (1 << CPU_FEAT_L1_CACHE) |
78bcae80e9SThomas Chou 		(gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0);
79bcae80e9SThomas Chou 
80bcae80e9SThomas Chou 	return 0;
81bcae80e9SThomas Chou }
82bcae80e9SThomas Chou 
83bcae80e9SThomas Chou static int altera_nios2_get_count(struct udevice *dev)
84bcae80e9SThomas Chou {
85bcae80e9SThomas Chou 	return 1;
86bcae80e9SThomas Chou }
87bcae80e9SThomas Chou 
88bcae80e9SThomas Chou static int altera_nios2_probe(struct udevice *dev)
89bcae80e9SThomas Chou {
90bcae80e9SThomas Chou 	const void *blob = gd->fdt_blob;
91bcae80e9SThomas Chou 	int node = dev->of_offset;
92bcae80e9SThomas Chou 
93bcae80e9SThomas Chou 	gd->cpu_clk = fdtdec_get_int(blob, node,
94bcae80e9SThomas Chou 		"clock-frequency", 0);
95bcae80e9SThomas Chou 	gd->arch.dcache_line_size = fdtdec_get_int(blob, node,
96bcae80e9SThomas Chou 		"dcache-line-size", 0);
97bcae80e9SThomas Chou 	gd->arch.icache_line_size = fdtdec_get_int(blob, node,
98bcae80e9SThomas Chou 		"icache-line-size", 0);
99bcae80e9SThomas Chou 	gd->arch.dcache_size = fdtdec_get_int(blob, node,
100bcae80e9SThomas Chou 		"dcache-size", 0);
101bcae80e9SThomas Chou 	gd->arch.icache_size = fdtdec_get_int(blob, node,
102bcae80e9SThomas Chou 		"icache-size", 0);
103bcae80e9SThomas Chou 	gd->arch.reset_addr = fdtdec_get_int(blob, node,
104bcae80e9SThomas Chou 		"altr,reset-addr", 0);
105bcae80e9SThomas Chou 	gd->arch.exception_addr = fdtdec_get_int(blob, node,
106bcae80e9SThomas Chou 		"altr,exception-addr", 0);
107bcae80e9SThomas Chou 	gd->arch.has_initda = fdtdec_get_int(blob, node,
108bcae80e9SThomas Chou 		"altr,has-initda", 0);
109bcae80e9SThomas Chou 	gd->arch.has_mmu = fdtdec_get_int(blob, node,
110bcae80e9SThomas Chou 		"altr,has-mmu", 0);
111bcae80e9SThomas Chou 	gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x8000000;
112bcae80e9SThomas Chou 
113bcae80e9SThomas Chou 	return 0;
114bcae80e9SThomas Chou }
115bcae80e9SThomas Chou 
116bcae80e9SThomas Chou static const struct cpu_ops altera_nios2_ops = {
117bcae80e9SThomas Chou 	.get_desc	= altera_nios2_get_desc,
118bcae80e9SThomas Chou 	.get_info	= altera_nios2_get_info,
119bcae80e9SThomas Chou 	.get_count	= altera_nios2_get_count,
120bcae80e9SThomas Chou };
121bcae80e9SThomas Chou 
122bcae80e9SThomas Chou static const struct udevice_id altera_nios2_ids[] = {
123bcae80e9SThomas Chou 	{ .compatible = "altr,nios2-1.0" },
124bcae80e9SThomas Chou 	{ .compatible = "altr,nios2-1.1" },
125bcae80e9SThomas Chou 	{ }
126bcae80e9SThomas Chou };
127bcae80e9SThomas Chou 
128bcae80e9SThomas Chou U_BOOT_DRIVER(altera_nios2) = {
129bcae80e9SThomas Chou 	.name		= "altera_nios2",
130bcae80e9SThomas Chou 	.id		= UCLASS_CPU,
131bcae80e9SThomas Chou 	.of_match	= altera_nios2_ids,
132bcae80e9SThomas Chou 	.probe		= altera_nios2_probe,
133bcae80e9SThomas Chou 	.ops		= &altera_nios2_ops,
134bcae80e9SThomas Chou 	.flags		= DM_FLAG_PRE_RELOC,
135bcae80e9SThomas Chou };
136