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",
41 [BOOT_LOADER_ROUTERBOOT]= "RouterBOOT"
45 * CPU settings detection
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)
53 static void __init detect_cpu_info(void)
59 reg = (uint32_t *)KSEG1ADDR(ADM5120_SWITCH_BASE+SWITCH_REG_CODE);
62 clks = CODE_GET_CLKS(code);
64 adm5120_info.product_code = CODE_GET_PC(code);
65 adm5120_info.revision = CODE_GET_REV(code);
67 adm5120_info.cpu_speed = CPU_SPEED_175;
69 adm5120_info.cpu_speed += 25000000;
71 adm5120_info.cpu_speed += 50000000;
73 adm5120_info.cpu_package = (CODE_GET_PK(code) == CODE_PK_BGA) ?
74 CPU_PACKAGE_BGA : CPU_PACKAGE_PQFP;
76 adm5120_info.nand_boot = CODE_GET_NAB(code);
81 * Boot loader detection routines
83 static int __init detect_cfe(void)
86 * This method only works, when we are booted directly from the CFE.
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;
93 /* Check for CFE by finding the CFE magic number */
94 if (cfe_seal != CFE_EPTSEAL) {
95 /* We are not booted from CFE */
99 /* cfe_a1_val must be 0, because only one CPU present in the ADM5120 SoC */
100 if (cfe_a1_val != 0) {
104 /* The cfe_handle, and the cfe_entry must be kernel mode addresses */
105 if ((cfe_handle < KSEG0) || (cfe_entry < KSEG0)) {
112 static int __init detect_uboot(void)
114 /* FIXME: not yet implemented */
118 static int __init detect_myloader(void)
120 struct mylo_system_params *sysp;
121 struct mylo_board_params *boardp;
122 struct mylo_partition_table *parts;
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);
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))
137 static int __init detect_routerboot(void)
139 /* FIXME: not yet implemented */
143 static int __init detect_bootloader(void)
146 return BOOT_LOADER_CFE;
149 return BOOT_LOADER_UBOOT;
151 if (detect_myloader())
152 return BOOT_LOADER_MYLOADER;
154 if (detect_routerboot())
155 return BOOT_LOADER_ROUTERBOOT;
157 return BOOT_LOADER_UNKNOWN;
163 static void __init detect_board_type(void)
165 switch(adm5120_info.boot_loader) {
166 case BOOT_LOADER_CFE:
167 adm5120_info.board_type = BOARD_TYPE_WP54G_WRT;
168 adm5120_info.iface_num = 2;
169 adm5120_info.has_usb = 0;
170 printk("Board is a Compex WP54G-WRT\n");
172 adm5120_info.board_type = BOARD_TYPE_UNKNOWN;
173 printk("Board type is unknown\n");
177 void __init adm5120_info_show(void)
179 printk("ADM%04X%s revision %d, running at %ldMHz\n",
180 adm5120_info.product_code,
181 (adm5120_info.cpu_package == CPU_PACKAGE_BGA) ? "" : "P",
182 adm5120_info.revision,
183 (adm5120_info.cpu_speed / 1000000)
185 printk("Boot loader is: %s\n", boot_loader_names[adm5120_info.boot_loader]);
186 printk("Booted from : %s flash\n", adm5120_info.nand_boot ? "NAND" : "NOR");
189 void __init adm5120_info_init(void)
192 adm5120_info.boot_loader = detect_bootloader();