Also forgot adding the adm5120_info file
[openwrt/svn-archive/archive.git] / target / linux / adm5120-2.6 / files / arch / mips / adm5120 / adm5120_info.c
1 /*
2 * Copyright (C) 2007 OpenWrt.org
3 * Copyright (C) Gabor Juhos
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
10
11 #include <linux/types.h>
12 #include <linux/autoconf.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15
16 #include <asm/bootinfo.h>
17 #include <asm/addrspace.h>
18
19 #include <adm5120_info.h>
20 #include <myloader.h>
21
22 /* boot loaders specific definitions */
23 #define CFE_EPTSEAL 0x43464531 /* CFE1 is the magic number to recognize CFE from other bootloaders */
24
25
26 struct adm5120_info adm5120_info = {
27 .cpu_speed = CPU_SPEED_175,
28 .cpu_package = CPU_PACKAGE_PQFP,
29 .boot_loader = BOOT_LOADER_UNKNOWN,
30 .board_type = BOARD_TYPE_UNKNOWN
31 };
32
33 static char *boot_loader_names[BOOT_LOADER_LAST+1] = {
34 [BOOT_LOADER_UNKNOWN] = "Unknown",
35 [BOOT_LOADER_CFE] = "CFE",
36 [BOOT_LOADER_UBOOT] = "U-Boot",
37 [BOOT_LOADER_MYLOADER] = "MyLoader"
38 };
39
40 /*
41 * Boot loader detection routines
42 */
43 static int __init detect_cfe(void)
44 {
45 /*
46 * This method only works, when we are booted directly from the CFE.
47 */
48 uint32_t cfe_handle = (uint32_t) fw_arg0;
49 uint32_t cfe_a1_val = (uint32_t) fw_arg1;
50 uint32_t cfe_entry = (uint32_t) fw_arg2;
51 uint32_t cfe_seal = (uint32_t) fw_arg3;
52
53 /* Check for CFE by finding the CFE magic number */
54 if (cfe_seal != CFE_EPTSEAL) {
55 /* We are not booted from CFE */
56 return 0;
57 }
58
59 /* cfe_a1_val must be 0, because only one CPU present in the ADM5120 SoC */
60 if (cfe_a1_val != 0) {
61 return 0;
62 }
63
64 /* The cfe_handle, and the cfe_entry must be kernel mode addresses */
65 if ((cfe_handle < KSEG0) || (cfe_entry < KSEG0)) {
66 return 0;
67 }
68
69 return 1;
70 }
71
72 static int __init detect_uboot(void)
73 {
74 /* FIXME: not yet implemented */
75 return 0;
76 }
77
78 static int __init detect_myloader(void)
79 {
80 struct mylo_system_params *sysp;
81 struct mylo_board_params *boardp;
82 struct mylo_partition_table *parts;
83
84 sysp = (struct mylo_system_params *)(MYLO_MIPS_SYS_PARAMS);
85 boardp = (struct mylo_board_params *)(MYLO_MIPS_BOARD_PARAMS);
86 parts = (struct mylo_partition_table *)(MYLO_MIPS_PARTITIONS);
87
88 /* Check for some magic numbers */
89 if ((sysp->magic != MYLO_MAGIC_SYS_PARAMS) ||
90 (boardp->magic != MYLO_MAGIC_BOARD_PARAMS) ||
91 (parts->magic != MYLO_MAGIC_PARTITIONS))
92 return 0;
93
94 return 1;
95 }
96
97 static int __init detect_bootloader(void)
98 {
99 if (detect_cfe())
100 return BOOT_LOADER_CFE;
101
102 if (detect_uboot())
103 return BOOT_LOADER_UBOOT;
104
105 if (detect_myloader())
106 return BOOT_LOADER_MYLOADER;
107
108 return BOOT_LOADER_UNKNOWN;
109 }
110
111 void __init adm5120_info_show(void)
112 {
113 printk("adm5120: boot loader is %s\n", boot_loader_names[adm5120_info.boot_loader]);
114 }
115
116 void __init adm5120_info_init(void)
117 {
118 adm5120_info.boot_loader = detect_bootloader();
119
120 adm5120_info_show();
121 }