1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Author: Huacai Chen <chenhuacai@loongson.cn>
4  *
5  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
6  */
7 #include <linux/acpi.h>
8 #include <linux/clk.h>
9 #include <linux/efi.h>
10 #include <linux/export.h>
11 #include <linux/memblock.h>
12 #include <linux/of_clk.h>
13 #include <asm/early_ioremap.h>
14 #include <asm/bootinfo.h>
15 #include <asm/loongson.h>
16 #include <asm/setup.h>
17 #include <asm/time.h>
18 
19 u64 efi_system_table;
20 struct loongson_system_configuration loongson_sysconf;
21 EXPORT_SYMBOL(loongson_sysconf);
22 
init_environ(void)23 void __init init_environ(void)
24 {
25 	int efi_boot = fw_arg0;
26 	char *cmdline = early_memremap_ro(fw_arg1, COMMAND_LINE_SIZE);
27 
28 	if (efi_boot)
29 		set_bit(EFI_BOOT, &efi.flags);
30 	else
31 		clear_bit(EFI_BOOT, &efi.flags);
32 
33 	strscpy(boot_command_line, cmdline, COMMAND_LINE_SIZE);
34 	strscpy(init_command_line, cmdline, COMMAND_LINE_SIZE);
35 	early_memunmap(cmdline, COMMAND_LINE_SIZE);
36 
37 	efi_system_table = fw_arg2;
38 }
39 
init_cpu_fullname(void)40 static int __init init_cpu_fullname(void)
41 {
42 	struct device_node *root;
43 	int cpu, ret;
44 	char *model;
45 
46 	/* Parsing cpuname from DTS model property */
47 	root = of_find_node_by_path("/");
48 	ret = of_property_read_string(root, "model", (const char **)&model);
49 	of_node_put(root);
50 	if (ret == 0)
51 		loongson_sysconf.cpuname = strsep(&model, " ");
52 
53 	if (loongson_sysconf.cpuname && !strncmp(loongson_sysconf.cpuname, "Loongson", 8)) {
54 		for (cpu = 0; cpu < NR_CPUS; cpu++)
55 			__cpu_full_name[cpu] = loongson_sysconf.cpuname;
56 	}
57 	return 0;
58 }
59 arch_initcall(init_cpu_fullname);
60 
fdt_cpu_clk_init(void)61 static int __init fdt_cpu_clk_init(void)
62 {
63 	struct clk *clk;
64 	struct device_node *np;
65 
66 	np = of_get_cpu_node(0, NULL);
67 	if (!np)
68 		return -ENODEV;
69 
70 	clk = of_clk_get(np, 0);
71 	if (IS_ERR(clk))
72 		return -ENODEV;
73 
74 	cpu_clock_freq = clk_get_rate(clk);
75 	clk_put(clk);
76 
77 	return 0;
78 }
79 late_initcall(fdt_cpu_clk_init);
80 
boardinfo_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)81 static ssize_t boardinfo_show(struct kobject *kobj,
82 			      struct kobj_attribute *attr, char *buf)
83 {
84 	return sprintf(buf,
85 		"BIOS Information\n"
86 		"Vendor\t\t\t: %s\n"
87 		"Version\t\t\t: %s\n"
88 		"ROM Size\t\t: %d KB\n"
89 		"Release Date\t\t: %s\n\n"
90 		"Board Information\n"
91 		"Manufacturer\t\t: %s\n"
92 		"Board Name\t\t: %s\n"
93 		"Family\t\t\t: LOONGSON64\n\n",
94 		b_info.bios_vendor, b_info.bios_version,
95 		b_info.bios_size, b_info.bios_release_date,
96 		b_info.board_vendor, b_info.board_name);
97 }
98 
99 static struct kobj_attribute boardinfo_attr = __ATTR(boardinfo, 0444,
100 						     boardinfo_show, NULL);
101 
boardinfo_init(void)102 static int __init boardinfo_init(void)
103 {
104 	struct kobject *loongson_kobj;
105 
106 	loongson_kobj = kobject_create_and_add("loongson", firmware_kobj);
107 
108 	return sysfs_create_file(loongson_kobj, &boardinfo_attr.attr);
109 }
110 late_initcall(boardinfo_init);
111