Rename mipsIRQ.S to int-handler to match the kernel naming convention, implement...
[librecmc/librecmc.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         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");
171                 default:
172                         adm5120_info.board_type = BOARD_TYPE_UNKNOWN;
173                         printk("Board type is unknown\n");
174         }
175 }
176
177 void __init adm5120_info_show(void)
178 {
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)
184                 );
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");
187 }
188
189 void __init adm5120_info_init(void)
190 {
191         detect_cpu_info();
192         adm5120_info.boot_loader = detect_bootloader();
193         detect_board_type();
194
195         adm5120_info_show();
196 }