Linux Audio

Check our new training course

Loading...
v4.6
 
  1/*
  2 *  linux/arch/h8300/kernel/setup.c
  3 *
  4 *  Copyright (C) 2001-2014 Yoshinori Sato <ysato@users.sourceforge.jp>
  5 */
  6
  7/*
  8 * This file handles the architecture-dependent parts of system setup
  9 */
 10
 11#include <linux/kernel.h>
 12#include <linux/sched.h>
 13#include <linux/delay.h>
 14#include <linux/interrupt.h>
 
 15#include <linux/mm.h>
 16#include <linux/fs.h>
 17#include <linux/console.h>
 18#include <linux/errno.h>
 19#include <linux/string.h>
 20#include <linux/bootmem.h>
 21#include <linux/seq_file.h>
 22#include <linux/init.h>
 23#include <linux/of.h>
 24#include <linux/of_fdt.h>
 25#include <linux/of_platform.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	int bootmap_size;
 74	unsigned long ram_start_pfn;
 75	unsigned long free_ram_start_pfn;
 76	unsigned long ram_end_pfn;
 77	struct memblock_region *region;
 78
 79	memory_end = memory_start = 0;
 80
 81	/* Find main memory where is the kernel */
 82	for_each_memblock(memory, region) {
 83		memory_start = region->base;
 84		memory_end = region->base + region->size;
 85	}
 86
 87	if (!memory_end)
 88		panic("No memory!");
 89
 90	ram_start_pfn = PFN_UP(memory_start);
 91	/* free_ram_start_pfn is first page after kernel */
 92	free_ram_start_pfn = PFN_UP(__pa(_end));
 93	ram_end_pfn = PFN_DOWN(memblock_end_of_DRAM());
 94
 95	max_pfn = ram_end_pfn;
 96
 97	/*
 98	 * give all the memory to the bootmap allocator,  tell it to put the
 99	 * boot mem_map at the start of memory
100	 */
101	bootmap_size = init_bootmem_node(NODE_DATA(0),
102					 free_ram_start_pfn,
103					 0,
104					 ram_end_pfn);
105	/*
106	 * free the usable memory,  we have to make sure we do not free
107	 * the bootmem bitmap so we then reserve it after freeing it :-)
108	 */
109	free_bootmem(PFN_PHYS(free_ram_start_pfn),
110		     (ram_end_pfn - free_ram_start_pfn) << PAGE_SHIFT);
111	reserve_bootmem(PFN_PHYS(free_ram_start_pfn), bootmap_size,
112			BOOTMEM_DEFAULT);
113
114	for_each_memblock(reserved, region) {
115		reserve_bootmem(region->base, region->size, BOOTMEM_DEFAULT);
116	}
117}
118
119void __init setup_arch(char **cmdline_p)
120{
121	unflatten_and_copy_device_tree();
122
123	init_mm.start_code = (unsigned long) _stext;
124	init_mm.end_code = (unsigned long) _etext;
125	init_mm.end_data = (unsigned long) _edata;
126	init_mm.brk = (unsigned long) 0;
127
128	pr_notice("\r\n\nuClinux " CPU "\n");
129	pr_notice("Flat model support (C) 1998,1999 Kenneth Albanowski, D. Jeff Dionne\n");
130
131	if (*command_line)
132		strcpy(boot_command_line, command_line);
133	*cmdline_p = boot_command_line;
134
135	parse_early_param();
136
137	bootmem_init();
138	/*
139	 * get kmalloc into gear
140	 */
141	paging_init();
142}
143
144/*
145 *	Get CPU information for use by the procfs.
146 */
147
148static int show_cpuinfo(struct seq_file *m, void *v)
149{
150	char *cpu;
151
152	cpu = CPU;
153
154	seq_printf(m,  "CPU:\t\t%s\n"
155		   "Clock:\t\t%lu.%1luMHz\n"
156		   "BogoMips:\t%lu.%02lu\n"
157		   "Calibration:\t%lu loops\n",
158		   cpu,
159		   freq/1000, freq%1000,
160		   (loops_per_jiffy*HZ)/500000,
161		   ((loops_per_jiffy*HZ)/5000)%100,
162		   (loops_per_jiffy*HZ));
163
164	return 0;
165}
166
167static void *c_start(struct seq_file *m, loff_t *pos)
168{
169	return *pos < num_possible_cpus() ?
170		((void *) 0x12345678) : NULL;
171}
172
173static void *c_next(struct seq_file *m, void *v, loff_t *pos)
174{
175	++*pos;
176	return c_start(m, pos);
177}
178
179static void c_stop(struct seq_file *m, void *v)
180{
181}
182
183const struct seq_operations cpuinfo_op = {
184	.start	= c_start,
185	.next	= c_next,
186	.stop	= c_stop,
187	.show	= show_cpuinfo,
188};
189
190static int __init device_probe(void)
191{
192	of_platform_populate(NULL, NULL, NULL, NULL);
193
194	return 0;
195}
196
197device_initcall(device_probe);
198
199#if defined(CONFIG_CPU_H8300H)
200#define get_wait(base, addr) ({		\
201	int baddr;			\
202	baddr = ((addr) / 0x200000 * 2);			     \
203	w *= (readw((base) + 2) & (3 << baddr)) + 1;		     \
204	})
205#endif
206#if defined(CONFIG_CPU_H8S)
207#define get_wait(base, addr) ({		\
208	int baddr;			\
209	baddr = ((addr) / 0x200000 * 16);			     \
210	w *= (readl((base) + 2) & (7 << baddr)) + 1;	\
211	})
212#endif
213
214static __init int access_timing(void)
215{
216	struct device_node *bsc;
217	void __iomem *base;
218	unsigned long addr = (unsigned long)&__delay;
219	int bit = 1 << (addr / 0x200000);
220	int w;
221
222	bsc = of_find_compatible_node(NULL, NULL, "renesas,h8300-bsc");
223	base = of_iomap(bsc, 0);
224	w = (readb(base + 0) & bit)?2:1;
225	if (readb(base + 1) & bit)
226		w *= get_wait(base, addr);
227	else
228		w *= 2;
229	return w * 3 / 2;
230}
231
232void __init calibrate_delay(void)
233{
234	struct device_node *cpu;
235	int freq;
236
237	cpu = of_find_compatible_node(NULL, NULL, "renesas,h8300");
238	of_property_read_s32(cpu, "clock-frequency", &freq);
239	loops_per_jiffy = freq / HZ / (access_timing() * 2);
240	pr_cont("%lu.%02lu BogoMIPS (lpj=%lu)\n",
241		loops_per_jiffy / (500000 / HZ),
242		(loops_per_jiffy / (5000 / HZ)) % 100, loops_per_jiffy);
243}
244
245
246void __init time_init(void)
247{
248	of_clk_init(NULL);
249	clocksource_probe();
250}
v5.4
  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}