c3590b2e95929cf994026e689c688cf3d3230bb4
[sfrench/cifs-2.6.git] / arch / h8300 / kernel / setup.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *  linux/arch/h8300/kernel/setup.c
4  *
5  *  Copyright (C) 2001-2014 Yoshinori Sato <ysato@users.sourceforge.jp>
6  */
7
8 /*
9  * This file handles the architecture-dependent parts of system setup
10  */
11
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/delay.h>
15 #include <linux/interrupt.h>
16 #include <linux/io.h>
17 #include <linux/mm.h>
18 #include <linux/fs.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>
24 #include <linux/of.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>
31
32 #include <asm/setup.h>
33 #include <asm/irq.h>
34 #include <asm/sections.h>
35 #include <asm/page.h>
36
37 #if defined(CONFIG_CPU_H8300H)
38 #define CPU "H8/300H"
39 #elif defined(CONFIG_CPU_H8S)
40 #define CPU "H8S"
41 #else
42 #define CPU "Unknown"
43 #endif
44
45 unsigned long memory_start;
46 unsigned long memory_end;
47 EXPORT_SYMBOL(memory_end);
48 static unsigned long freq;
49 extern char __dtb_start[];
50
51 #ifdef CONFIG_VT
52 struct screen_info screen_info;
53 #endif
54
55 char __initdata command_line[COMMAND_LINE_SIZE];
56
57 void sim_console_register(void);
58
59 void __init h8300_fdt_init(void *fdt, char *bootargs)
60 {
61         if (!fdt)
62                 fdt = __dtb_start;
63         else
64                 strcpy(command_line, bootargs);
65
66         early_init_dt_scan(fdt);
67         memblock_allow_resize();
68 }
69
70 static void __init bootmem_init(void)
71 {
72         memory_end = memory_start = 0;
73
74         /* Find main memory where is the kernel */
75         memory_start = memblock_start_of_DRAM();
76         memory_end = memblock_end_of_DRAM();
77
78         if (!memory_end)
79                 panic("No memory!");
80
81         /* setup bootmem globals (we use no_bootmem, but mm still depends on this) */
82         min_low_pfn = PFN_UP(memory_start);
83         max_low_pfn = PFN_DOWN(memory_end);
84         max_pfn = max_low_pfn;
85
86         memblock_reserve(__pa(_stext), _end - _stext);
87
88         early_init_fdt_reserve_self();
89         early_init_fdt_scan_reserved_mem();
90
91         memblock_dump_all();
92 }
93
94 void __init setup_arch(char **cmdline_p)
95 {
96         unflatten_and_copy_device_tree();
97
98         init_mm.start_code = (unsigned long) _stext;
99         init_mm.end_code = (unsigned long) _etext;
100         init_mm.end_data = (unsigned long) _edata;
101         init_mm.brk = (unsigned long) 0;
102
103         pr_notice("\r\n\nuClinux " CPU "\n");
104         pr_notice("Flat model support (C) 1998,1999 Kenneth Albanowski, D. Jeff Dionne\n");
105
106         if (*command_line)
107                 strcpy(boot_command_line, command_line);
108         *cmdline_p = boot_command_line;
109
110         parse_early_param();
111
112         bootmem_init();
113         /*
114          * get kmalloc into gear
115          */
116         paging_init();
117 }
118
119 /*
120  *      Get CPU information for use by the procfs.
121  */
122
123 static int show_cpuinfo(struct seq_file *m, void *v)
124 {
125         char *cpu;
126
127         cpu = CPU;
128
129         seq_printf(m,  "CPU:\t\t%s\n"
130                    "Clock:\t\t%lu.%1luMHz\n"
131                    "BogoMips:\t%lu.%02lu\n"
132                    "Calibration:\t%lu loops\n",
133                    cpu,
134                    freq/1000, freq%1000,
135                    (loops_per_jiffy*HZ)/500000,
136                    ((loops_per_jiffy*HZ)/5000)%100,
137                    (loops_per_jiffy*HZ));
138
139         return 0;
140 }
141
142 static void *c_start(struct seq_file *m, loff_t *pos)
143 {
144         return *pos < num_possible_cpus() ?
145                 ((void *) 0x12345678) : NULL;
146 }
147
148 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
149 {
150         ++*pos;
151         return c_start(m, pos);
152 }
153
154 static void c_stop(struct seq_file *m, void *v)
155 {
156 }
157
158 const struct seq_operations cpuinfo_op = {
159         .start  = c_start,
160         .next   = c_next,
161         .stop   = c_stop,
162         .show   = show_cpuinfo,
163 };
164
165 #if defined(CONFIG_CPU_H8300H)
166 #define get_wait(base, addr) ({         \
167         int baddr;                      \
168         baddr = ((addr) / 0x200000 * 2);                             \
169         w *= (readw((base) + 2) & (3 << baddr)) + 1;                 \
170         })
171 #endif
172 #if defined(CONFIG_CPU_H8S)
173 #define get_wait(base, addr) ({         \
174         int baddr;                      \
175         baddr = ((addr) / 0x200000 * 16);                            \
176         w *= (readl((base) + 2) & (7 << baddr)) + 1;    \
177         })
178 #endif
179
180 static __init int access_timing(void)
181 {
182         struct device_node *bsc;
183         void __iomem *base;
184         unsigned long addr = (unsigned long)&__delay;
185         int bit = 1 << (addr / 0x200000);
186         int w;
187
188         bsc = of_find_compatible_node(NULL, NULL, "renesas,h8300-bsc");
189         base = of_iomap(bsc, 0);
190         w = (readb(base + 0) & bit)?2:1;
191         if (readb(base + 1) & bit)
192                 w *= get_wait(base, addr);
193         else
194                 w *= 2;
195         return w * 3 / 2;
196 }
197
198 void __init calibrate_delay(void)
199 {
200         struct device_node *cpu;
201         int freq;
202
203         cpu = of_find_compatible_node(NULL, NULL, "renesas,h8300");
204         of_property_read_s32(cpu, "clock-frequency", &freq);
205         loops_per_jiffy = freq / HZ / (access_timing() * 2);
206         pr_cont("%lu.%02lu BogoMIPS (lpj=%lu)\n",
207                 loops_per_jiffy / (500000 / HZ),
208                 (loops_per_jiffy / (5000 / HZ)) % 100, loops_per_jiffy);
209 }
210
211
212 void __init time_init(void)
213 {
214         of_clk_init(NULL);
215         timer_probe();
216 }