Use CONFIG_CMDLINE instead of hardcoded kernel command line
[openwrt.git] / target / linux / adm5120-2.6 / files / arch / mips / adm5120 / adm5120_info.c
1 /*
2 * $Id$
3 *
4 * Copyright (C) 2007 OpenWrt.org
5 * Copyright (C) 2007 Gabor Juhos <juhosg@freemail.hu>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13 #include <linux/types.h>
14 #include <linux/autoconf.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17
18 #include <asm/bootinfo.h>
19 #include <asm/addrspace.h>
20
21 #include <adm5120_info.h>
22 #include <adm5120_defs.h>
23 #include <adm5120_switch.h>
24 #include <myloader.h>
25
26 /* boot loaders specific definitions */
27 #define CFE_EPTSEAL 0x43464531 /* CFE1 is the magic number to recognize CFE from other bootloaders */
28
29 struct adm5120_info adm5120_info = {
30 .cpu_speed = CPU_SPEED_175,
31 .cpu_package = CPU_PACKAGE_PQFP,
32 .boot_loader = BOOT_LOADER_UNKNOWN,
33 .board_type = BOARD_TYPE_UNKNOWN
34 };
35
36 static char *boot_loader_names[BOOT_LOADER_LAST+1] = {
37 [BOOT_LOADER_UNKNOWN] = "Unknown",
38 [BOOT_LOADER_CFE] = "CFE",
39 [BOOT_LOADER_UBOOT] = "U-Boot",
40 [BOOT_LOADER_MYLOADER] = "MyLoader",
41 [BOOT_LOADER_ROUTERBOOT]= "RouterBOOT"
42 };
43
44 /*
45 * CPU settings detection
46 */
47 #define CODE_GET_PC(c) ((c) & CODE_PC_MASK)
48 #define CODE_GET_REV(c) (((c) >> CODE_REV_SHIFT) & CODE_REV_MASK)
49 #define CODE_GET_PK(c) (((c) >> CODE_PK_SHIFT) & CODE_PK_MASK)
50 #define CODE_GET_CLKS(c) (((c) >> CODE_CLKS_SHIFT) & CODE_CLKS_MASK)
51 #define CODE_GET_NAB(c) (((c) & CODE_NAB) != 0)
52
53 static void __init detect_cpu_info(void)
54 {
55 uint32_t *reg;
56 uint32_t code;
57 uint32_t clks;
58
59 reg = (uint32_t *)KSEG1ADDR(ADM5120_SWITCH_BASE+SWITCH_REG_CODE);
60 code = *reg;
61
62 clks = CODE_GET_CLKS(code);
63
64 adm5120_info.product_code = CODE_GET_PC(code);
65 adm5120_info.revision = CODE_GET_REV(code);
66
67 adm5120_info.cpu_speed = CPU_SPEED_175;
68 if (clks & 1)
69 adm5120_info.cpu_speed += 25000000;
70 if (clks & 2)
71 adm5120_info.cpu_speed += 50000000;
72
73 adm5120_info.cpu_package = (CODE_GET_PK(code) == CODE_PK_BGA) ?
74 CPU_PACKAGE_BGA : CPU_PACKAGE_PQFP;
75
76 adm5120_info.nand_boot = CODE_GET_NAB(code);
77
78 }
79
80 /*
81 * Boot loader detection routines
82 */
83 static int __init detect_cfe(void)
84 {
85 /*
86 * This method only works, when we are booted directly from the CFE.
87 */
88 uint32_t cfe_handle = (uint32_t) fw_arg0;
89 uint32_t cfe_a1_val = (uint32_t) fw_arg1;
90 uint32_t cfe_entry = (uint32_t) fw_arg2;
91 uint32_t cfe_seal = (uint32_t) fw_arg3;
92
93 /* Check for CFE by finding the CFE magic number */
94 if (cfe_seal != CFE_EPTSEAL) {
95 /* We are not booted from CFE */
96 return 0;
97 }
98
99 /* cfe_a1_val must be 0, because only one CPU present in the ADM5120 SoC */
100 if (cfe_a1_val != 0) {
101 return 0;
102 }
103
104 /* The cfe_handle, and the cfe_entry must be kernel mode addresses */
105 if ((cfe_handle < KSEG0) || (cfe_entry < KSEG0)) {
106 return 0;
107 }
108
109 return 1;
110 }
111
112 static int __init detect_uboot(void)
113 {
114 /* FIXME: not yet implemented */
115 return 0;
116 }
117
118 static int __init detect_myloader(void)
119 {
120 struct mylo_system_params *sysp;
121 struct mylo_board_params *boardp;
122 struct mylo_partition_table *parts;
123
124 sysp = (struct mylo_system_params *)(MYLO_MIPS_SYS_PARAMS);
125 boardp = (struct mylo_board_params *)(MYLO_MIPS_BOARD_PARAMS);
126 parts = (struct mylo_partition_table *)(MYLO_MIPS_PARTITIONS);
127
128 /* Check for some magic numbers */
129 if ((sysp->magic != MYLO_MAGIC_SYS_PARAMS) ||
130 (boardp->magic != MYLO_MAGIC_BOARD_PARAMS) ||
131 (parts->magic != MYLO_MAGIC_PARTITIONS))
132 return 0;
133
134 return 1;
135 }
136
137 static int __init detect_routerboot(void)
138 {
139 /* FIXME: not yet implemented */
140 return 0;
141 }
142
143 static int __init detect_bootloader(void)
144 {
145 if (detect_cfe())
146 return BOOT_LOADER_CFE;
147
148 if (detect_uboot())
149 return BOOT_LOADER_UBOOT;
150
151 if (detect_myloader())
152 return BOOT_LOADER_MYLOADER;
153
154 if (detect_routerboot())
155 return BOOT_LOADER_ROUTERBOOT;
156
157 return BOOT_LOADER_UNKNOWN;
158 }
159
160 /*
161 * Board detection
162 */
163 static void __init detect_board_type(void)
164 {
165 /* FIXME: not yet implemented */
166 }
167
168 void __init adm5120_info_show(void)
169 {
170 printk("ADM%04X%s revision %d, running at %ldMHz\n",
171 adm5120_info.product_code,
172 (adm5120_info.cpu_package == CPU_PACKAGE_BGA) ? "" : "P",
173 adm5120_info.revision,
174 (adm5120_info.cpu_speed / 1000000)
175 );
176 printk("Boot loader is: %s\n", boot_loader_names[adm5120_info.boot_loader]);
177 printk("Booted from : %s flash\n", adm5120_info.nand_boot ? "NAND" : "NOR");
178 }
179
180 void __init adm5120_info_init(void)
181 {
182 detect_cpu_info();
183 adm5120_info.boot_loader = detect_bootloader();
184 detect_board_type();
185
186 adm5120_info_show();
187 }
This page took 0.0641 seconds and 5 git commands to generate.