4 * Copyright (C) 2007 OpenWrt.org
5 * Copyright (C) 2007 Gabor Juhos <juhosg@freemail.hu>
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.
13 #include <linux/types.h>
14 #include <linux/autoconf.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
18 #include <asm/bootinfo.h>
19 #include <asm/addrspace.h>
21 #include <adm5120_info.h>
22 #include <adm5120_defs.h>
23 #include <adm5120_switch.h>
26 /* boot loaders specific definitions */
27 #define CFE_EPTSEAL 0x43464531 /* CFE1 is the magic number to recognize CFE from other bootloaders */
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
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"
44 * CPU settings detection
46 #define CODE_GET_PC(c) ((c) & CODE_PC_MASK)
47 #define CODE_GET_REV(c) (((c) >> CODE_REV_SHIFT) & CODE_REV_MASK)
48 #define CODE_GET_PK(c) (((c) >> CODE_PK_SHIFT) & CODE_PK_MASK)
49 #define CODE_GET_CLKS(c) (((c) >> CODE_CLKS_SHIFT) & CODE_CLKS_MASK)
50 #define CODE_GET_NAB(c) (((c) & CODE_NAB) != 0)
52 static void __init detect_cpu_info(void)
58 reg = (uint32_t *)KSEG1ADDR(ADM5120_SWITCH_BASE+SWITCH_REG_CODE);
61 clks = CODE_GET_CLKS(code);
63 adm5120_info.product_code = CODE_GET_PC(code);
64 adm5120_info.revision = CODE_GET_REV(code);
66 adm5120_info.cpu_speed = CPU_SPEED_175;
68 adm5120_info.cpu_speed += 25000000;
70 adm5120_info.cpu_speed += 50000000;
72 adm5120_info.cpu_package = (CODE_GET_PK(code) == CODE_PK_BGA) ?
73 CPU_PACKAGE_BGA : CPU_PACKAGE_PQFP;
75 adm5120_info.nand_boot = CODE_GET_NAB(code);
80 * Boot loader detection routines
82 static int __init detect_cfe(void)
85 * This method only works, when we are booted directly from the CFE.
87 uint32_t cfe_handle = (uint32_t) fw_arg0;
88 uint32_t cfe_a1_val = (uint32_t) fw_arg1;
89 uint32_t cfe_entry = (uint32_t) fw_arg2;
90 uint32_t cfe_seal = (uint32_t) fw_arg3;
92 /* Check for CFE by finding the CFE magic number */
93 if (cfe_seal != CFE_EPTSEAL) {
94 /* We are not booted from CFE */
98 /* cfe_a1_val must be 0, because only one CPU present in the ADM5120 SoC */
99 if (cfe_a1_val != 0) {
103 /* The cfe_handle, and the cfe_entry must be kernel mode addresses */
104 if ((cfe_handle < KSEG0) || (cfe_entry < KSEG0)) {
111 static int __init detect_uboot(void)
113 /* FIXME: not yet implemented */
117 static int __init detect_myloader(void)
119 struct mylo_system_params *sysp;
120 struct mylo_board_params *boardp;
121 struct mylo_partition_table *parts;
123 sysp = (struct mylo_system_params *)(MYLO_MIPS_SYS_PARAMS);
124 boardp = (struct mylo_board_params *)(MYLO_MIPS_BOARD_PARAMS);
125 parts = (struct mylo_partition_table *)(MYLO_MIPS_PARTITIONS);
127 /* Check for some magic numbers */
128 if ((sysp->magic != MYLO_MAGIC_SYS_PARAMS) ||
129 (boardp->magic != MYLO_MAGIC_BOARD_PARAMS) ||
130 (parts->magic != MYLO_MAGIC_PARTITIONS))
136 static int __init detect_routerboot(void)
138 /* FIXME: not yet implemented */
142 static int __init detect_bootloader(void)
145 return BOOT_LOADER_CFE;
148 return BOOT_LOADER_UBOOT;
150 if (detect_myloader())
151 return BOOT_LOADER_MYLOADER;
153 if (detect_routerboot())
154 return BOOT_LOADER_ROUTERBOOT;
156 return BOOT_LOADER_UNKNOWN;
162 static void __init detect_board_type(void)
164 /* FIXME: not yet implemented */
167 void __init adm5120_info_show(void)
169 printk("ADM%04X%s revision %d, running at %ldMHz\n",
170 adm5120_info.product_code,
171 (adm5120_info.cpu_package == CPU_PACKAGE_BGA) ? "" : "P",
172 adm5120_info.revision,
173 (adm5120_info.cpu_speed / 1000000)
175 printk("Boot loader is: %s\n", boot_loader_names[adm5120_info.boot_loader]);
176 printk("Booted from : %s flash\n", adm5120_info.nand_boot ? "NAND" : "NOR");
179 void __init adm5120_info_init(void)
182 adm5120_info.boot_loader = detect_bootloader();