1 // SPDX-License-Identifier: GPL-2.0
3 * linux/arch/h8300/kernel/setup.c
5 * Copyright (C) 2001-2014 Yoshinori Sato <ysato@users.sourceforge.jp>
9 * This file handles the architecture-dependent parts of system setup
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/delay.h>
15 #include <linux/interrupt.h>
19 #include <linux/console.h>
20 #include <linux/errno.h>
21 #include <linux/string.h>
22 #include <linux/seq_file.h>
23 #include <linux/init.h>
25 #include <linux/of_fdt.h>
26 #include <linux/of_address.h>
27 #include <linux/clk-provider.h>
28 #include <linux/memblock.h>
29 #include <linux/screen_info.h>
30 #include <linux/clocksource.h>
32 #include <asm/setup.h>
34 #include <asm/pgtable.h>
35 #include <asm/sections.h>
38 #if defined(CONFIG_CPU_H8300H)
40 #elif defined(CONFIG_CPU_H8S)
46 unsigned long memory_start
;
47 unsigned long memory_end
;
48 EXPORT_SYMBOL(memory_end
);
49 static unsigned long freq
;
50 extern char __dtb_start
[];
53 struct screen_info screen_info
;
56 char __initdata command_line
[COMMAND_LINE_SIZE
];
58 void sim_console_register(void);
60 void __init
h8300_fdt_init(void *fdt
, char *bootargs
)
65 strcpy(command_line
, bootargs
);
67 early_init_dt_scan(fdt
);
68 memblock_allow_resize();
71 static void __init
bootmem_init(void)
73 struct memblock_region
*region
;
75 memory_end
= memory_start
= 0;
77 /* Find main memory where is the kernel */
78 for_each_memblock(memory
, region
) {
79 memory_start
= region
->base
;
80 memory_end
= region
->base
+ region
->size
;
86 /* setup bootmem globals (we use no_bootmem, but mm still depends on this) */
87 min_low_pfn
= PFN_UP(memory_start
);
88 max_low_pfn
= PFN_DOWN(memblock_end_of_DRAM());
89 max_pfn
= max_low_pfn
;
91 memblock_reserve(__pa(_stext
), _end
- _stext
);
93 early_init_fdt_reserve_self();
94 early_init_fdt_scan_reserved_mem();
99 void __init
setup_arch(char **cmdline_p
)
101 unflatten_and_copy_device_tree();
103 init_mm
.start_code
= (unsigned long) _stext
;
104 init_mm
.end_code
= (unsigned long) _etext
;
105 init_mm
.end_data
= (unsigned long) _edata
;
106 init_mm
.brk
= (unsigned long) 0;
108 pr_notice("\r\n\nuClinux " CPU
"\n");
109 pr_notice("Flat model support (C) 1998,1999 Kenneth Albanowski, D. Jeff Dionne\n");
112 strcpy(boot_command_line
, command_line
);
113 *cmdline_p
= boot_command_line
;
119 * get kmalloc into gear
125 * Get CPU information for use by the procfs.
128 static int show_cpuinfo(struct seq_file
*m
, void *v
)
134 seq_printf(m
, "CPU:\t\t%s\n"
135 "Clock:\t\t%lu.%1luMHz\n"
136 "BogoMips:\t%lu.%02lu\n"
137 "Calibration:\t%lu loops\n",
139 freq
/1000, freq
%1000,
140 (loops_per_jiffy
*HZ
)/500000,
141 ((loops_per_jiffy
*HZ
)/5000)%100,
142 (loops_per_jiffy
*HZ
));
147 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
149 return *pos
< num_possible_cpus() ?
150 ((void *) 0x12345678) : NULL
;
153 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
156 return c_start(m
, pos
);
159 static void c_stop(struct seq_file
*m
, void *v
)
163 const struct seq_operations cpuinfo_op
= {
167 .show
= show_cpuinfo
,
170 #if defined(CONFIG_CPU_H8300H)
171 #define get_wait(base, addr) ({ \
173 baddr = ((addr) / 0x200000 * 2); \
174 w *= (readw((base) + 2) & (3 << baddr)) + 1; \
177 #if defined(CONFIG_CPU_H8S)
178 #define get_wait(base, addr) ({ \
180 baddr = ((addr) / 0x200000 * 16); \
181 w *= (readl((base) + 2) & (7 << baddr)) + 1; \
185 static __init
int access_timing(void)
187 struct device_node
*bsc
;
189 unsigned long addr
= (unsigned long)&__delay
;
190 int bit
= 1 << (addr
/ 0x200000);
193 bsc
= of_find_compatible_node(NULL
, NULL
, "renesas,h8300-bsc");
194 base
= of_iomap(bsc
, 0);
195 w
= (readb(base
+ 0) & bit
)?2:1;
196 if (readb(base
+ 1) & bit
)
197 w
*= get_wait(base
, addr
);
203 void __init
calibrate_delay(void)
205 struct device_node
*cpu
;
208 cpu
= of_find_compatible_node(NULL
, NULL
, "renesas,h8300");
209 of_property_read_s32(cpu
, "clock-frequency", &freq
);
210 loops_per_jiffy
= freq
/ HZ
/ (access_timing() * 2);
211 pr_cont("%lu.%02lu BogoMIPS (lpj=%lu)\n",
212 loops_per_jiffy
/ (500000 / HZ
),
213 (loops_per_jiffy
/ (5000 / HZ
)) % 100, loops_per_jiffy
);
217 void __init
time_init(void)