Loading...
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/pgtable.h>
35#include <asm/sections.h>
36#include <asm/page.h>
37
38#if defined(CONFIG_CPU_H8300H)
39#define CPU "H8/300H"
40#elif defined(CONFIG_CPU_H8S)
41#define CPU "H8S"
42#else
43#define CPU "Unknown"
44#endif
45
46unsigned long memory_start;
47unsigned long memory_end;
48EXPORT_SYMBOL(memory_end);
49static unsigned long freq;
50extern char __dtb_start[];
51
52#ifdef CONFIG_VT
53struct screen_info screen_info;
54#endif
55
56char __initdata command_line[COMMAND_LINE_SIZE];
57
58void sim_console_register(void);
59
60void __init h8300_fdt_init(void *fdt, char *bootargs)
61{
62 if (!fdt)
63 fdt = __dtb_start;
64 else
65 strcpy(command_line, bootargs);
66
67 early_init_dt_scan(fdt);
68 memblock_allow_resize();
69}
70
71static void __init bootmem_init(void)
72{
73 struct memblock_region *region;
74
75 memory_end = memory_start = 0;
76
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;
81 }
82
83 if (!memory_end)
84 panic("No memory!");
85
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;
90
91 memblock_reserve(__pa(_stext), _end - _stext);
92
93 early_init_fdt_reserve_self();
94 early_init_fdt_scan_reserved_mem();
95
96 memblock_dump_all();
97}
98
99void __init setup_arch(char **cmdline_p)
100{
101 unflatten_and_copy_device_tree();
102
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;
107
108 pr_notice("\r\n\nuClinux " CPU "\n");
109 pr_notice("Flat model support (C) 1998,1999 Kenneth Albanowski, D. Jeff Dionne\n");
110
111 if (*command_line)
112 strcpy(boot_command_line, command_line);
113 *cmdline_p = boot_command_line;
114
115 parse_early_param();
116
117 bootmem_init();
118 /*
119 * get kmalloc into gear
120 */
121 paging_init();
122}
123
124/*
125 * Get CPU information for use by the procfs.
126 */
127
128static int show_cpuinfo(struct seq_file *m, void *v)
129{
130 char *cpu;
131
132 cpu = CPU;
133
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",
138 cpu,
139 freq/1000, freq%1000,
140 (loops_per_jiffy*HZ)/500000,
141 ((loops_per_jiffy*HZ)/5000)%100,
142 (loops_per_jiffy*HZ));
143
144 return 0;
145}
146
147static void *c_start(struct seq_file *m, loff_t *pos)
148{
149 return *pos < num_possible_cpus() ?
150 ((void *) 0x12345678) : NULL;
151}
152
153static void *c_next(struct seq_file *m, void *v, loff_t *pos)
154{
155 ++*pos;
156 return c_start(m, pos);
157}
158
159static void c_stop(struct seq_file *m, void *v)
160{
161}
162
163const struct seq_operations cpuinfo_op = {
164 .start = c_start,
165 .next = c_next,
166 .stop = c_stop,
167 .show = show_cpuinfo,
168};
169
170#if defined(CONFIG_CPU_H8300H)
171#define get_wait(base, addr) ({ \
172 int baddr; \
173 baddr = ((addr) / 0x200000 * 2); \
174 w *= (readw((base) + 2) & (3 << baddr)) + 1; \
175 })
176#endif
177#if defined(CONFIG_CPU_H8S)
178#define get_wait(base, addr) ({ \
179 int baddr; \
180 baddr = ((addr) / 0x200000 * 16); \
181 w *= (readl((base) + 2) & (7 << baddr)) + 1; \
182 })
183#endif
184
185static __init int access_timing(void)
186{
187 struct device_node *bsc;
188 void __iomem *base;
189 unsigned long addr = (unsigned long)&__delay;
190 int bit = 1 << (addr / 0x200000);
191 int w;
192
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);
198 else
199 w *= 2;
200 return w * 3 / 2;
201}
202
203void __init calibrate_delay(void)
204{
205 struct device_node *cpu;
206 int freq;
207
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);
214}
215
216
217void __init time_init(void)
218{
219 of_clk_init(NULL);
220 timer_probe();
221}
1/*
2 * linux/arch/h8300/kernel/setup.c
3 *
4 * Copyleft ()) 2000 James D. Schettine {james@telos-systems.com}
5 * Copyright (C) 1999,2000 Greg Ungerer (gerg@snapgear.com)
6 * Copyright (C) 1998,1999 D. Jeff Dionne <jeff@lineo.ca>
7 * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>
8 * Copyright (C) 1995 Hamish Macdonald
9 * Copyright (C) 2000 Lineo Inc. (www.lineo.com)
10 * Copyright (C) 2001 Lineo, Inc. <www.lineo.com>
11 *
12 * H8/300 porting Yoshinori Sato <ysato@users.sourceforge.jp>
13 */
14
15/*
16 * This file handles the architecture-dependent parts of system setup
17 */
18
19#include <linux/kernel.h>
20#include <linux/sched.h>
21#include <linux/delay.h>
22#include <linux/interrupt.h>
23#include <linux/mm.h>
24#include <linux/fs.h>
25#include <linux/fb.h>
26#include <linux/console.h>
27#include <linux/genhd.h>
28#include <linux/errno.h>
29#include <linux/string.h>
30#include <linux/major.h>
31#include <linux/bootmem.h>
32#include <linux/seq_file.h>
33#include <linux/init.h>
34
35#include <asm/setup.h>
36#include <asm/irq.h>
37#include <asm/pgtable.h>
38#include <asm/sections.h>
39
40#if defined(__H8300H__)
41#define CPU "H8/300H"
42#include <asm/regs306x.h>
43#endif
44
45#if defined(__H8300S__)
46#define CPU "H8S"
47#include <asm/regs267x.h>
48#endif
49
50#define STUBSIZE 0xc000
51
52unsigned long rom_length;
53unsigned long memory_start;
54unsigned long memory_end;
55
56char __initdata command_line[COMMAND_LINE_SIZE];
57
58extern int _ramstart, _ramend;
59extern char _target_name[];
60extern void h8300_gpio_init(void);
61
62#if (defined(CONFIG_H8300H_SIM) || defined(CONFIG_H8S_SIM)) \
63 && defined(CONFIG_GDB_MAGICPRINT)
64/* printk with gdb service */
65static void gdb_console_output(struct console *c, const char *msg, unsigned len)
66{
67 for (; len > 0; len--) {
68 asm("mov.w %0,r2\n\t"
69 "jsr @0xc4"::"r"(*msg++):"er2");
70 }
71}
72
73/*
74 * Setup initial baud/bits/parity. We do two things here:
75 * - construct a cflag setting for the first rs_open()
76 * - initialize the serial port
77 * Return non-zero if we didn't find a serial port.
78 */
79static int __init gdb_console_setup(struct console *co, char *options)
80{
81 return 0;
82}
83
84static const struct console gdb_console = {
85 .name = "gdb_con",
86 .write = gdb_console_output,
87 .device = NULL,
88 .setup = gdb_console_setup,
89 .flags = CON_PRINTBUFFER,
90 .index = -1,
91};
92#endif
93
94void __init setup_arch(char **cmdline_p)
95{
96 int bootmap_size;
97
98 memory_start = (unsigned long) &_ramstart;
99
100 /* allow for ROMFS on the end of the kernel */
101 if (memcmp((void *)memory_start, "-rom1fs-", 8) == 0) {
102#if defined(CONFIG_BLK_DEV_INITRD)
103 initrd_start = memory_start;
104 initrd_end = memory_start += be32_to_cpu(((unsigned long *) (memory_start))[2]);
105#else
106 memory_start += be32_to_cpu(((unsigned long *) memory_start)[2]);
107#endif
108 }
109 memory_start = PAGE_ALIGN(memory_start);
110#if !defined(CONFIG_BLKDEV_RESERVE)
111 memory_end = (unsigned long) &_ramend; /* by now the stack is part of the init task */
112#if defined(CONFIG_GDB_DEBUG)
113 memory_end -= STUBSIZE;
114#endif
115#else
116 if ((memory_end < CONFIG_BLKDEV_RESERVE_ADDRESS) &&
117 (memory_end > CONFIG_BLKDEV_RESERVE_ADDRESS))
118 /* overlap userarea */
119 memory_end = CONFIG_BLKDEV_RESERVE_ADDRESS;
120#endif
121
122 init_mm.start_code = (unsigned long) _stext;
123 init_mm.end_code = (unsigned long) _etext;
124 init_mm.end_data = (unsigned long) _edata;
125 init_mm.brk = (unsigned long) 0;
126
127#if (defined(CONFIG_H8300H_SIM) || defined(CONFIG_H8S_SIM)) && defined(CONFIG_GDB_MAGICPRINT)
128 register_console((struct console *)&gdb_console);
129#endif
130
131 printk(KERN_INFO "\r\n\nuClinux " CPU "\n");
132 printk(KERN_INFO "Target Hardware: %s\n",_target_name);
133 printk(KERN_INFO "Flat model support (C) 1998,1999 Kenneth Albanowski, D. Jeff Dionne\n");
134 printk(KERN_INFO "H8/300 series support by Yoshinori Sato <ysato@users.sourceforge.jp>\n");
135
136#ifdef DEBUG
137 printk(KERN_DEBUG "KERNEL -> TEXT=0x%p-0x%p DATA=0x%p-0x%p "
138 "BSS=0x%p-0x%p\n", _stext, _etext, _sdata, _edata, __bss_start,
139 __bss_stop);
140 printk(KERN_DEBUG "KERNEL -> ROMFS=0x%p-0x%06lx MEM=0x%06lx-0x%06lx "
141 "STACK=0x%06lx-0x%p\n", __bss_stop, memory_start, memory_start,
142 memory_end, memory_end, &_ramend);
143#endif
144
145#ifdef CONFIG_DEFAULT_CMDLINE
146 /* set from default command line */
147 if (*command_line == '\0')
148 strcpy(command_line,CONFIG_KERNEL_COMMAND);
149#endif
150 /* Keep a copy of command line */
151 *cmdline_p = &command_line[0];
152 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
153 boot_command_line[COMMAND_LINE_SIZE-1] = 0;
154
155#ifdef DEBUG
156 if (strlen(*cmdline_p))
157 printk(KERN_DEBUG "Command line: '%s'\n", *cmdline_p);
158#endif
159
160 /*
161 * give all the memory to the bootmap allocator, tell it to put the
162 * boot mem_map at the start of memory
163 */
164 bootmap_size = init_bootmem_node(
165 NODE_DATA(0),
166 memory_start >> PAGE_SHIFT, /* map goes here */
167 PAGE_OFFSET >> PAGE_SHIFT, /* 0 on coldfire */
168 memory_end >> PAGE_SHIFT);
169 /*
170 * free the usable memory, we have to make sure we do not free
171 * the bootmem bitmap so we then reserve it after freeing it :-)
172 */
173 free_bootmem(memory_start, memory_end - memory_start);
174 reserve_bootmem(memory_start, bootmap_size, BOOTMEM_DEFAULT);
175 /*
176 * get kmalloc into gear
177 */
178 paging_init();
179 h8300_gpio_init();
180#if defined(CONFIG_H8300_AKI3068NET) && defined(CONFIG_IDE)
181 {
182#define AREABIT(addr) (1 << (((addr) >> 21) & 7))
183 /* setup BSC */
184 volatile unsigned char *abwcr = (volatile unsigned char *)ABWCR;
185 volatile unsigned char *cscr = (volatile unsigned char *)CSCR;
186 *abwcr &= ~(AREABIT(CONFIG_H8300_IDE_BASE) | AREABIT(CONFIG_H8300_IDE_ALT));
187 *cscr |= (AREABIT(CONFIG_H8300_IDE_BASE) | AREABIT(CONFIG_H8300_IDE_ALT)) | 0x0f;
188 }
189#endif
190#ifdef DEBUG
191 printk(KERN_DEBUG "Done setup_arch\n");
192#endif
193}
194
195/*
196 * Get CPU information for use by the procfs.
197 */
198
199static int show_cpuinfo(struct seq_file *m, void *v)
200{
201 char *cpu;
202 int mode;
203 u_long clockfreq;
204
205 cpu = CPU;
206 mode = *(volatile unsigned char *)MDCR & 0x07;
207
208 clockfreq = CONFIG_CPU_CLOCK;
209
210 seq_printf(m, "CPU:\t\t%s (mode:%d)\n"
211 "Clock:\t\t%lu.%1luMHz\n"
212 "BogoMips:\t%lu.%02lu\n"
213 "Calibration:\t%lu loops\n",
214 cpu,mode,
215 clockfreq/1000,clockfreq%1000,
216 (loops_per_jiffy*HZ)/500000,((loops_per_jiffy*HZ)/5000)%100,
217 (loops_per_jiffy*HZ));
218
219 return 0;
220}
221
222static void *c_start(struct seq_file *m, loff_t *pos)
223{
224 return *pos < NR_CPUS ? ((void *) 0x12345678) : NULL;
225}
226
227static void *c_next(struct seq_file *m, void *v, loff_t *pos)
228{
229 ++*pos;
230 return c_start(m, pos);
231}
232
233static void c_stop(struct seq_file *m, void *v)
234{
235}
236
237const struct seq_operations cpuinfo_op = {
238 .start = c_start,
239 .next = c_next,
240 .stop = c_stop,
241 .show = show_cpuinfo,
242};