xref: /rk3399_rockchip-uboot/arch/nios2/cpu/cpu.c (revision bcae80e9551bc0ba2d67e78bda57b9283b4bab12)
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>
9*bcae80e9SThomas Chou #include <cpu.h>
10*bcae80e9SThomas Chou #include <dm.h>
11*bcae80e9SThomas Chou #include <errno.h>
12f956ad98SJoachim Foerster #include <asm/cache.h>
1337e4dafaSPeter Tyser 
145ff10aa7SThomas Chou DECLARE_GLOBAL_DATA_PTR;
155ff10aa7SThomas Chou 
1637e4dafaSPeter Tyser #if defined (CONFIG_SYS_NIOS_SYSID_BASE)
1737e4dafaSPeter Tyser extern void display_sysid (void);
1837e4dafaSPeter Tyser #endif /* CONFIG_SYS_NIOS_SYSID_BASE */
1937e4dafaSPeter Tyser 
205ff10aa7SThomas Chou #ifdef CONFIG_DISPLAY_CPUINFO
215ff10aa7SThomas Chou int print_cpuinfo(void)
2237e4dafaSPeter Tyser {
2337e4dafaSPeter Tyser 	printf ("CPU   : Nios-II\n");
2437e4dafaSPeter Tyser #if !defined(CONFIG_SYS_NIOS_SYSID_BASE)
2537e4dafaSPeter Tyser 	printf ("SYSID : <unknown>\n");
2637e4dafaSPeter Tyser #else
2737e4dafaSPeter Tyser 	display_sysid ();
2837e4dafaSPeter Tyser #endif
2937e4dafaSPeter Tyser 	return (0);
3037e4dafaSPeter Tyser }
315ff10aa7SThomas Chou #endif /* CONFIG_DISPLAY_CPUINFO */
3237e4dafaSPeter Tyser 
33882b7d72SMike Frysinger int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
3437e4dafaSPeter Tyser {
3537e4dafaSPeter Tyser 	disable_interrupts();
367a6a7d10SThomas Chou 	/* indirect call to go beyond 256MB limitation of toolchain */
377a6a7d10SThomas Chou 	nios2_callr(CONFIG_SYS_RESET_ADDR);
387a6a7d10SThomas Chou 	return 0;
3937e4dafaSPeter Tyser }
40f956ad98SJoachim Foerster 
41f956ad98SJoachim Foerster int dcache_status(void)
42f956ad98SJoachim Foerster {
43f956ad98SJoachim Foerster 	return 1;
44f956ad98SJoachim Foerster }
45f956ad98SJoachim Foerster 
46f956ad98SJoachim Foerster void dcache_enable(void)
47f956ad98SJoachim Foerster {
48f956ad98SJoachim Foerster 	flush_dcache(CONFIG_SYS_DCACHE_SIZE, CONFIG_SYS_DCACHELINE_SIZE);
49f956ad98SJoachim Foerster }
50f956ad98SJoachim Foerster 
51f956ad98SJoachim Foerster void dcache_disable(void)
52f956ad98SJoachim Foerster {
53f956ad98SJoachim Foerster 	flush_dcache(CONFIG_SYS_DCACHE_SIZE, CONFIG_SYS_DCACHELINE_SIZE);
54f956ad98SJoachim Foerster }
555ff10aa7SThomas Chou 
56*bcae80e9SThomas Chou int arch_cpu_init_dm(void)
575ff10aa7SThomas Chou {
58*bcae80e9SThomas Chou 	struct udevice *dev;
59*bcae80e9SThomas Chou 	int ret;
60*bcae80e9SThomas Chou 
61*bcae80e9SThomas Chou 	ret = uclass_first_device(UCLASS_CPU, &dev);
62*bcae80e9SThomas Chou 	if (ret)
63*bcae80e9SThomas Chou 		return ret;
64*bcae80e9SThomas Chou 	if (!dev)
65*bcae80e9SThomas Chou 		return -ENODEV;
66*bcae80e9SThomas Chou 
675ff10aa7SThomas Chou 	gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
685ff10aa7SThomas Chou 
695ff10aa7SThomas Chou 	return 0;
705ff10aa7SThomas Chou }
71*bcae80e9SThomas Chou 
72*bcae80e9SThomas Chou static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size)
73*bcae80e9SThomas Chou {
74*bcae80e9SThomas Chou 	const char *cpu_name = "Nios-II";
75*bcae80e9SThomas Chou 
76*bcae80e9SThomas Chou 	if (size < strlen(cpu_name))
77*bcae80e9SThomas Chou 		return -ENOSPC;
78*bcae80e9SThomas Chou 	strcpy(buf, cpu_name);
79*bcae80e9SThomas Chou 
80*bcae80e9SThomas Chou 	return 0;
81*bcae80e9SThomas Chou }
82*bcae80e9SThomas Chou 
83*bcae80e9SThomas Chou static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info)
84*bcae80e9SThomas Chou {
85*bcae80e9SThomas Chou 	info->cpu_freq = gd->cpu_clk;
86*bcae80e9SThomas Chou 	info->features = (1 << CPU_FEAT_L1_CACHE) |
87*bcae80e9SThomas Chou 		(gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0);
88*bcae80e9SThomas Chou 
89*bcae80e9SThomas Chou 	return 0;
90*bcae80e9SThomas Chou }
91*bcae80e9SThomas Chou 
92*bcae80e9SThomas Chou static int altera_nios2_get_count(struct udevice *dev)
93*bcae80e9SThomas Chou {
94*bcae80e9SThomas Chou 	return 1;
95*bcae80e9SThomas Chou }
96*bcae80e9SThomas Chou 
97*bcae80e9SThomas Chou static int altera_nios2_probe(struct udevice *dev)
98*bcae80e9SThomas Chou {
99*bcae80e9SThomas Chou 	const void *blob = gd->fdt_blob;
100*bcae80e9SThomas Chou 	int node = dev->of_offset;
101*bcae80e9SThomas Chou 
102*bcae80e9SThomas Chou 	gd->cpu_clk = fdtdec_get_int(blob, node,
103*bcae80e9SThomas Chou 		"clock-frequency", 0);
104*bcae80e9SThomas Chou 	gd->arch.dcache_line_size = fdtdec_get_int(blob, node,
105*bcae80e9SThomas Chou 		"dcache-line-size", 0);
106*bcae80e9SThomas Chou 	gd->arch.icache_line_size = fdtdec_get_int(blob, node,
107*bcae80e9SThomas Chou 		"icache-line-size", 0);
108*bcae80e9SThomas Chou 	gd->arch.dcache_size = fdtdec_get_int(blob, node,
109*bcae80e9SThomas Chou 		"dcache-size", 0);
110*bcae80e9SThomas Chou 	gd->arch.icache_size = fdtdec_get_int(blob, node,
111*bcae80e9SThomas Chou 		"icache-size", 0);
112*bcae80e9SThomas Chou 	gd->arch.reset_addr = fdtdec_get_int(blob, node,
113*bcae80e9SThomas Chou 		"altr,reset-addr", 0);
114*bcae80e9SThomas Chou 	gd->arch.exception_addr = fdtdec_get_int(blob, node,
115*bcae80e9SThomas Chou 		"altr,exception-addr", 0);
116*bcae80e9SThomas Chou 	gd->arch.has_initda = fdtdec_get_int(blob, node,
117*bcae80e9SThomas Chou 		"altr,has-initda", 0);
118*bcae80e9SThomas Chou 	gd->arch.has_mmu = fdtdec_get_int(blob, node,
119*bcae80e9SThomas Chou 		"altr,has-mmu", 0);
120*bcae80e9SThomas Chou 	gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x8000000;
121*bcae80e9SThomas Chou 
122*bcae80e9SThomas Chou 	return 0;
123*bcae80e9SThomas Chou }
124*bcae80e9SThomas Chou 
125*bcae80e9SThomas Chou static const struct cpu_ops altera_nios2_ops = {
126*bcae80e9SThomas Chou 	.get_desc	= altera_nios2_get_desc,
127*bcae80e9SThomas Chou 	.get_info	= altera_nios2_get_info,
128*bcae80e9SThomas Chou 	.get_count	= altera_nios2_get_count,
129*bcae80e9SThomas Chou };
130*bcae80e9SThomas Chou 
131*bcae80e9SThomas Chou static const struct udevice_id altera_nios2_ids[] = {
132*bcae80e9SThomas Chou 	{ .compatible = "altr,nios2-1.0" },
133*bcae80e9SThomas Chou 	{ .compatible = "altr,nios2-1.1" },
134*bcae80e9SThomas Chou 	{ }
135*bcae80e9SThomas Chou };
136*bcae80e9SThomas Chou 
137*bcae80e9SThomas Chou U_BOOT_DRIVER(altera_nios2) = {
138*bcae80e9SThomas Chou 	.name		= "altera_nios2",
139*bcae80e9SThomas Chou 	.id		= UCLASS_CPU,
140*bcae80e9SThomas Chou 	.of_match	= altera_nios2_ids,
141*bcae80e9SThomas Chou 	.probe		= altera_nios2_probe,
142*bcae80e9SThomas Chou 	.ops		= &altera_nios2_ops,
143*bcae80e9SThomas Chou 	.flags		= DM_FLAG_PRE_RELOC,
144*bcae80e9SThomas Chou };
145