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>
18 #include <linux/console.h>
19 #include <linux/errno.h>
20 #include <linux/string.h>
21 #include <linux/bootmem.h>
22 #include <linux/seq_file.h>
23 #include <linux/init.h>
25 #include <linux/of_fdt.h>
26 #include <linux/of_platform.h>
27 #include <linux/of_address.h>
28 #include <linux/clk-provider.h>
29 #include <linux/memblock.h>
30 #include <linux/screen_info.h>
31 #include <linux/clocksource.h>
33 #include <asm/setup.h>
35 #include <asm/pgtable.h>
36 #include <asm/sections.h>
39 #if defined(CONFIG_CPU_H8300H)
41 #elif defined(CONFIG_CPU_H8S)
47 unsigned long memory_start
;
48 unsigned long memory_end
;
49 EXPORT_SYMBOL(memory_end
);
50 static unsigned long freq
;
51 extern char __dtb_start
[];
54 struct screen_info screen_info
;
57 char __initdata command_line
[COMMAND_LINE_SIZE
];
59 void sim_console_register(void);
61 void __init
h8300_fdt_init(void *fdt
, char *bootargs
)
66 strcpy(command_line
, bootargs
);
68 early_init_dt_scan(fdt
);
69 memblock_allow_resize();
72 static void __init
bootmem_init(void)
75 unsigned long ram_start_pfn
;
76 unsigned long free_ram_start_pfn
;
77 unsigned long ram_end_pfn
;
78 struct memblock_region
*region
;
80 memory_end
= memory_start
= 0;
82 /* Find main memory where is the kernel */
83 for_each_memblock(memory
, region
) {
84 memory_start
= region
->base
;
85 memory_end
= region
->base
+ region
->size
;
91 ram_start_pfn
= PFN_UP(memory_start
);
92 /* free_ram_start_pfn is first page after kernel */
93 free_ram_start_pfn
= PFN_UP(__pa(_end
));
94 ram_end_pfn
= PFN_DOWN(memblock_end_of_DRAM());
96 max_pfn
= ram_end_pfn
;
99 * give all the memory to the bootmap allocator, tell it to put the
100 * boot mem_map at the start of memory
102 bootmap_size
= init_bootmem_node(NODE_DATA(0),
107 * free the usable memory, we have to make sure we do not free
108 * the bootmem bitmap so we then reserve it after freeing it :-)
110 free_bootmem(PFN_PHYS(free_ram_start_pfn
),
111 (ram_end_pfn
- free_ram_start_pfn
) << PAGE_SHIFT
);
112 reserve_bootmem(PFN_PHYS(free_ram_start_pfn
), bootmap_size
,
115 for_each_memblock(reserved
, region
) {
116 reserve_bootmem(region
->base
, region
->size
, BOOTMEM_DEFAULT
);
120 void __init
setup_arch(char **cmdline_p
)
122 unflatten_and_copy_device_tree();
124 init_mm
.start_code
= (unsigned long) _stext
;
125 init_mm
.end_code
= (unsigned long) _etext
;
126 init_mm
.end_data
= (unsigned long) _edata
;
127 init_mm
.brk
= (unsigned long) 0;
129 pr_notice("\r\n\nuClinux " CPU
"\n");
130 pr_notice("Flat model support (C) 1998,1999 Kenneth Albanowski, D. Jeff Dionne\n");
133 strcpy(boot_command_line
, command_line
);
134 *cmdline_p
= boot_command_line
;
140 * get kmalloc into gear
146 * Get CPU information for use by the procfs.
149 static int show_cpuinfo(struct seq_file
*m
, void *v
)
155 seq_printf(m
, "CPU:\t\t%s\n"
156 "Clock:\t\t%lu.%1luMHz\n"
157 "BogoMips:\t%lu.%02lu\n"
158 "Calibration:\t%lu loops\n",
160 freq
/1000, freq
%1000,
161 (loops_per_jiffy
*HZ
)/500000,
162 ((loops_per_jiffy
*HZ
)/5000)%100,
163 (loops_per_jiffy
*HZ
));
168 static void *c_start(struct seq_file
*m
, loff_t
*pos
)
170 return *pos
< num_possible_cpus() ?
171 ((void *) 0x12345678) : NULL
;
174 static void *c_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
177 return c_start(m
, pos
);
180 static void c_stop(struct seq_file
*m
, void *v
)
184 const struct seq_operations cpuinfo_op
= {
188 .show
= show_cpuinfo
,
191 static int __init
device_probe(void)
193 of_platform_populate(NULL
, NULL
, NULL
, NULL
);
198 device_initcall(device_probe
);
200 #if defined(CONFIG_CPU_H8300H)
201 #define get_wait(base, addr) ({ \
203 baddr = ((addr) / 0x200000 * 2); \
204 w *= (readw((base) + 2) & (3 << baddr)) + 1; \
207 #if defined(CONFIG_CPU_H8S)
208 #define get_wait(base, addr) ({ \
210 baddr = ((addr) / 0x200000 * 16); \
211 w *= (readl((base) + 2) & (7 << baddr)) + 1; \
215 static __init
int access_timing(void)
217 struct device_node
*bsc
;
219 unsigned long addr
= (unsigned long)&__delay
;
220 int bit
= 1 << (addr
/ 0x200000);
223 bsc
= of_find_compatible_node(NULL
, NULL
, "renesas,h8300-bsc");
224 base
= of_iomap(bsc
, 0);
225 w
= (readb(base
+ 0) & bit
)?2:1;
226 if (readb(base
+ 1) & bit
)
227 w
*= get_wait(base
, addr
);
233 void __init
calibrate_delay(void)
235 struct device_node
*cpu
;
238 cpu
= of_find_compatible_node(NULL
, NULL
, "renesas,h8300");
239 of_property_read_s32(cpu
, "clock-frequency", &freq
);
240 loops_per_jiffy
= freq
/ HZ
/ (access_timing() * 2);
241 pr_cont("%lu.%02lu BogoMIPS (lpj=%lu)\n",
242 loops_per_jiffy
/ (500000 / HZ
),
243 (loops_per_jiffy
/ (5000 / HZ
)) % 100, loops_per_jiffy
);
247 void __init
time_init(void)