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>
17 #include <linux/string.h>
19 #include <asm/bootinfo.h>
20 #include <asm/addrspace.h>
22 #include <asm/mach-adm5120/adm5120_defs.h>
23 #include <asm/mach-adm5120/adm5120_switch.h>
24 #include <asm/mach-adm5120/adm5120_info.h>
25 #include <asm/mach-adm5120/myloader.h>
26 #include <asm/mach-adm5120/routerboot.h>
27 #include <asm/mach-adm5120/zynos.h>
32 struct adm5120_board adm5120_board
;
33 unsigned int adm5120_boot_loader
;
35 unsigned int adm5120_product_code
;
36 unsigned int adm5120_revision
;
37 unsigned int adm5120_package
;
38 unsigned int adm5120_nand_boot
;
39 unsigned long adm5120_speed
;
44 static char *boot_loader_names
[BOOT_LOADER_LAST
+1] = {
45 [BOOT_LOADER_UNKNOWN
] = "Unknown",
46 [BOOT_LOADER_CFE
] = "CFE",
47 [BOOT_LOADER_UBOOT
] = "U-Boot",
48 [BOOT_LOADER_MYLOADER
] = "MyLoader",
49 [BOOT_LOADER_ROUTERBOOT
]= "RouterBOOT",
50 [BOOT_LOADER_BOOTBASE
] = "Bootbase"
53 static struct adm5120_board __initdata adm5120_boards
[] = {
55 .name
= "Compex NetPassage 27G",
56 .mach_type
= MACH_ADM5120_NP27G
,
59 .flash0_size
= 4*1024*1024,
62 .name
= "Compex NetPassage 28G",
63 .mach_type
= MACH_ADM5120_NP28G
,
66 .flash0_size
= 4*1024*1024,
69 .name
= "Compex NP28G (HotSpot)",
70 .mach_type
= MACH_ADM5120_NP28GHS
,
73 .flash0_size
= 4*1024*1024,
76 .name
= "Compex WP54AG",
77 .mach_type
= MACH_ADM5120_WP54AG
,
80 .flash0_size
= 4*1024*1024,
83 .name
= "Compex WP54G",
84 .mach_type
= MACH_ADM5120_WP54G
,
87 .flash0_size
= 4*1024*1024,
90 .name
= "Compex WP54G-WRT",
91 .mach_type
= MACH_ADM5120_WP54G_WRT
,
94 .flash0_size
= 4*1024*1024,
97 .name
= "Compex WP54G v1C",
98 .mach_type
= MACH_ADM5120_WP54Gv1C
,
101 .flash0_size
= 2*1024*1024,
104 .name
= "Compex WPP54AG",
105 .mach_type
= MACH_ADM5120_WPP54AG
,
108 .flash0_size
= 4*1024*1024,
111 .name
= "Compex WPP54G",
112 .mach_type
= MACH_ADM5120_WPP54G
,
115 .flash0_size
= 4*1024*1024,
118 .name
= "RouterBOARD 111",
119 .mach_type
= MACH_ADM5120_RB_111
,
122 .flash0_size
= 128*1024,
125 .name
= "RouterBOARD 112",
126 .mach_type
= MACH_ADM5120_RB_112
,
129 .flash0_size
= 128*1024,
132 .name
= "RouterBOARD 133",
133 .mach_type
= MACH_ADM5120_RB_133
,
136 .flash0_size
= 128*1024,
139 .name
= "RouterBOARD 133C",
140 .mach_type
= MACH_ADM5120_RB_133C
,
143 .flash0_size
= 128*1024,
146 .name
= "RouterBOARD 150",
147 .mach_type
= MACH_ADM5120_RB_150
,
150 .flash0_size
= 128*1024,
153 .name
= "RouterBOARD 153",
154 .mach_type
= MACH_ADM5120_RB_153
,
157 .flash0_size
= 128*1024,
160 .name
= "ZyXEL ES-2108",
161 .mach_type
= MACH_ADM5120_ES2108
,
164 .flash0_size
= 4*1024*1024,
167 .name
= "ZyXEL ES-2108-F",
168 .mach_type
= MACH_ADM5120_ES2108F
,
171 .flash0_size
= 4*1024*1024,
174 .name
= "ZyXEL ES-2108-G",
175 .mach_type
= MACH_ADM5120_ES2108G
,
178 .flash0_size
= 4*1024*1024,
181 .name
= "ZyXEL ES-2108-LC",
182 .mach_type
= MACH_ADM5120_ES2108LC
,
185 .flash0_size
= 4*1024*1024,
188 .name
= "ZyXEL ES-2108PWR",
189 .mach_type
= MACH_ADM5120_ES2108PWR
,
192 .flash0_size
= 4*1024*1024,
195 .name
= "ZyXEL HomeSafe 100/100W",
196 .mach_type
= MACH_ADM5120_HS100
,
199 .flash0_size
= 4*1024*1024,
202 .name
= "ZyXEL Prestige 334",
203 .mach_type
= MACH_ADM5120_P334
,
206 .flash0_size
= 2*1024*1024,
209 .name
= "ZyXEL Prestige 334U",
210 .mach_type
= MACH_ADM5120_P334U
,
213 .flash0_size
= 4*1024*1024,
216 .name
= "ZyXEL Prestige 334W",
217 .mach_type
= MACH_ADM5120_P334W
,
220 .flash0_size
= 2*1024*1024,
223 .name
= "ZyXEL Prestige 334WH",
224 .mach_type
= MACH_ADM5120_P334WH
,
227 .flash0_size
= 4*1024*1024,
230 .name
= "ZyXEL Prestige 334WHD",
231 .mach_type
= MACH_ADM5120_P334WHD
,
234 .flash0_size
= 4*1024*1024,
237 .name
= "ZyXEL Prestige 334WT",
238 .mach_type
= MACH_ADM5120_P334WT
,
241 .flash0_size
= 4*1024*1024,
244 .name
= "ZyXEL Prestige 335/335WT",
245 .mach_type
= MACH_ADM5120_P335
,
248 .flash0_size
= 4*1024*1024,
251 .name
= "ZyXEL Prestige 335Plus",
252 .mach_type
= MACH_ADM5120_P335PLUS
,
255 .flash0_size
= 4*1024*1024,
258 .name
= "ZyXEL Prestige 335U",
259 .mach_type
= MACH_ADM5120_P335U
,
262 .flash0_size
= 4*1024*1024,
265 .name
= "Unknown ADM5120 board",
266 .mach_type
= MACH_ADM5120_UNKNOWN
,
273 #define DUMMY_BOARD() {.mach_type = MACH_ADM5120_UNKNOWN}
280 unsigned long mach_type
;
284 #define MYLO_BOARD(v,d,sv,sd,mt) { .vid = (v), .did = (d), .svid = (sv), \
285 .sdid = (sd), .mach_type = (mt) }
287 #define COMPEX_BOARD(d,mt) MYLO_BOARD(VENID_COMPEX,(d),VENID_COMPEX,(d),(mt))
289 static struct mylo_board __initdata mylo_boards
[] = {
290 COMPEX_BOARD(DEVID_COMPEX_NP27G
, MACH_ADM5120_NP27G
),
291 COMPEX_BOARD(DEVID_COMPEX_NP28G
, MACH_ADM5120_NP28G
),
292 COMPEX_BOARD(DEVID_COMPEX_NP28GHS
, MACH_ADM5120_NP28GHS
),
293 COMPEX_BOARD(DEVID_COMPEX_WP54G
, MACH_ADM5120_WP54G
),
294 COMPEX_BOARD(DEVID_COMPEX_WP54Gv1C
, MACH_ADM5120_WP54Gv1C
),
295 COMPEX_BOARD(DEVID_COMPEX_WP54AG
, MACH_ADM5120_WP54AG
),
296 COMPEX_BOARD(DEVID_COMPEX_WPP54G
, MACH_ADM5120_WPP54G
),
297 COMPEX_BOARD(DEVID_COMPEX_WPP54AG
, MACH_ADM5120_WPP54AG
),
301 #define ROUTERBOARD_NAME_LEN 16
304 unsigned long mach_type
;
305 char name
[ROUTERBOARD_NAME_LEN
];
308 #define ROUTERBOARD(n, mt) { .name = (n), .mach_type = (mt) }
309 static struct routerboard __initdata routerboards
[] = {
310 ROUTERBOARD("111", MACH_ADM5120_RB_111
),
311 ROUTERBOARD("112", MACH_ADM5120_RB_112
),
312 ROUTERBOARD("133", MACH_ADM5120_RB_133
),
313 ROUTERBOARD("133C", MACH_ADM5120_RB_133C
),
314 ROUTERBOARD("miniROUTER", MACH_ADM5120_RB_150
),
315 ROUTERBOARD("153", MACH_ADM5120_RB_150
),
320 unsigned long mach_type
;
321 unsigned int vendor_id
;
325 #define ZYNOS_BOARD(vi, bi, mt) { .vendor_id = (vi), .board_id = (bi), \
328 #define ZYXEL_BOARD(bi, mt) ZYNOS_BOARD(ZYNOS_VENDOR_ID_ZYXEL, bi, mt)
329 #define DLINK_BOARD(bi, mt) ZYNOS_BOARD(ZYNOS_VENDOR_ID_DLINK, bi, mt)
330 #define LUCENT_BOARD(bi, mt) ZYNOS_BOARD(ZYNOS_VENDOR_ID_LUCENT, bi, mt)
332 static struct zynos_board __initdata zynos_boards
[] = {
333 ZYXEL_BOARD(ZYNOS_BOARD_HS100
, MACH_ADM5120_HS100
),
334 ZYXEL_BOARD(ZYNOS_BOARD_P334
, MACH_ADM5120_P334
),
335 ZYXEL_BOARD(ZYNOS_BOARD_P334U
, MACH_ADM5120_P334U
),
336 ZYXEL_BOARD(ZYNOS_BOARD_P334W
, MACH_ADM5120_P334W
),
337 ZYXEL_BOARD(ZYNOS_BOARD_P334WH
, MACH_ADM5120_P334WH
),
338 ZYXEL_BOARD(ZYNOS_BOARD_P334WHD
, MACH_ADM5120_P334WHD
),
339 ZYXEL_BOARD(ZYNOS_BOARD_P334WT
, MACH_ADM5120_P334WT
),
340 ZYXEL_BOARD(ZYNOS_BOARD_P335
, MACH_ADM5120_P335
),
341 ZYXEL_BOARD(ZYNOS_BOARD_P335PLUS
, MACH_ADM5120_P335PLUS
),
342 ZYXEL_BOARD(ZYNOS_BOARD_P335U
, MACH_ADM5120_P335U
),
349 static inline u16
read_le16(void *buf
)
354 return ((u16
)p
[0] + ((u16
)p
[1] << 8));
357 static inline u32
read_le32(void *buf
)
362 return ((u32
)p
[0] + ((u32
)p
[1] << 8) + ((u32
)p
[2] << 16) +
366 static inline u16
read_be16(void *buf
)
371 return (((u16
)p
[0] << 8) + (u16
)p
[1]);
374 static inline u32
read_be32(void *buf
)
379 return (((u32
)p
[0] << 24) + ((u32
)p
[1] << 16) + ((u32
)p
[2] << 8) +
386 #define CFE_EPTSEAL 0x43464531 /* CFE1 is the magic number to recognize CFE
387 from other bootloaders */
389 static int __init
cfe_present(void)
392 * This method only works, when we are booted directly from the CFE.
394 u32 cfe_handle
= (u32
) fw_arg0
;
395 u32 cfe_a1_val
= (u32
) fw_arg1
;
396 u32 cfe_entry
= (u32
) fw_arg2
;
397 u32 cfe_seal
= (u32
) fw_arg3
;
399 /* Check for CFE by finding the CFE magic number */
400 if (cfe_seal
!= CFE_EPTSEAL
) {
401 /* We are not booted from CFE */
405 /* cfe_a1_val must be 0, because only one CPU present in the ADM5120 */
406 if (cfe_a1_val
!= 0) {
410 /* The cfe_handle, and the cfe_entry must be kernel mode addresses */
411 if ((cfe_handle
< KSEG0
) || (cfe_entry
< KSEG0
)) {
418 static unsigned long __init
cfe_detect_board(void)
420 return MACH_ADM5120_WP54G_WRT
;
424 * MyLoader based boards
426 #define SYS_PARAMS_ADDR KSEG1ADDR(ADM5120_SRAM0_BASE+0x0F000)
427 #define BOARD_PARAMS_ADDR KSEG1ADDR(ADM5120_SRAM0_BASE+0x0F800)
428 #define PART_TABLE_ADDR KSEG1ADDR(ADM5120_SRAM0_BASE+0x10000)
430 static unsigned long __init
myloader_detect_board(void)
432 struct mylo_system_params
*sysp
;
433 struct mylo_board_params
*boardp
;
434 struct mylo_partition_table
*parts
;
435 struct mylo_board
*board
;
438 ret
= MACH_ADM5120_UNKNOWN
;
440 sysp
= (struct mylo_system_params
*)(SYS_PARAMS_ADDR
);
441 boardp
= (struct mylo_board_params
*)(BOARD_PARAMS_ADDR
);
442 parts
= (struct mylo_partition_table
*)(PART_TABLE_ADDR
);
444 /* Check for some magic numbers */
445 if ((le32_to_cpu(sysp
->magic
) != MYLO_MAGIC_SYS_PARAMS
) ||
446 (le32_to_cpu(boardp
->magic
) != MYLO_MAGIC_BOARD_PARAMS
) ||
447 (le32_to_cpu(parts
->magic
) != MYLO_MAGIC_PARTITIONS
))
450 for (board
= mylo_boards
; board
->mach_type
!= MACH_ADM5120_UNKNOWN
;
452 if ((le16_to_cpu(sysp
->vid
) == board
->vid
) &&
453 (le16_to_cpu(sysp
->did
) == board
->did
) &&
454 (le16_to_cpu(sysp
->svid
) == board
->svid
) &&
455 (le16_to_cpu(sysp
->sdid
) == board
->sdid
)) {
456 ret
= board
->mach_type
;
461 /* assume MyLoader as the boot-loader */
462 adm5120_boot_loader
= BOOT_LOADER_MYLOADER
;
469 * RouterBOOT based boards
471 static int __init
routerboot_load_hs(u8
*buf
, u16 buflen
,
472 struct rb_hard_settings
*hs
)
481 if (read_le32(buf
) != RB_MAGIC_HARD
)
484 /* skip magic value */
492 if (id
== RB_ID_TERMINATOR
|| buflen
< 2)
495 len
= read_le16(buf
);
503 case RB_ID_BIOS_VERSION
:
504 hs
->bios_ver
= (char *)buf
;
506 case RB_ID_BOARD_NAME
:
507 hs
->name
= (char *)buf
;
509 case RB_ID_MEMORY_SIZE
:
510 hs
->mem_size
= read_le32(buf
);
512 case RB_ID_MAC_ADDRESS_COUNT
:
513 hs
->mac_count
= read_le32(buf
);
515 case RB_ID_MAC_ADDRESS_PACK
:
516 hs
->mac_count
= len
/RB_MAC_SIZE
;
517 if (hs
->mac_count
> RB_MAX_MAC_COUNT
)
518 hs
->mac_count
= RB_MAX_MAC_COUNT
;
520 for (i
=0; i
< hs
->mac_count
; i
++) {
521 for (j
=0; j
< RB_MAC_SIZE
; j
++)
522 hs
->macs
[i
][j
] = mac
[j
];
536 #define RB_BS_OFFS 0x14
537 #define RB_OFFS_MAX (128*1024)
539 static unsigned long __init
routerboot_detect_board(void)
541 struct routerboard
*board
;
542 struct rb_hard_settings hs
;
543 struct rb_bios_settings
*bs
;
548 ret
= MACH_ADM5120_UNKNOWN
;
550 base
= (u8
*)KSEG1ADDR(ADM5120_SRAM0_BASE
);
551 bs
= (struct rb_bios_settings
*)(base
+ RB_BS_OFFS
);
553 off
= read_le32(&bs
->hs_offs
);
554 len
= read_le32(&bs
->hs_size
);
555 if (off
> RB_OFFS_MAX
)
558 memset(&hs
, 0, sizeof(hs
));
559 if (routerboot_load_hs(base
+off
, len
, &hs
) != 0)
562 /* assume RouterBOOT as the boot-loader */
563 adm5120_boot_loader
= BOOT_LOADER_ROUTERBOOT
;
568 for (board
= routerboards
; board
->mach_type
!= MACH_ADM5120_UNKNOWN
;
570 if (strncmp(board
->name
, hs
.name
, strlen(board
->name
)) == 0) {
571 ret
= board
->mach_type
;
582 static inline u32
zynos_dbgarea_present(u8
*data
)
586 t
= read_be32(data
+5);
587 if (t
!= ZYNOS_MAGIC_DBGAREA1
)
590 t
= read_be32(data
+9);
591 if (t
!= ZYNOS_MAGIC_DBGAREA2
)
597 #define CHECK_VENDOR(n) (strnicmp(vendor,(n),strlen(n)) == 0)
599 static inline unsigned int zynos_get_vendor_id(struct zynos_board_info
*info
)
601 unsigned char vendor
[ZYNOS_NAME_LEN
];
604 for (i
=0; i
<ZYNOS_NAME_LEN
; i
++)
605 vendor
[i
]=info
->vendor
[i
];
607 if CHECK_VENDOR(ZYNOS_VENDOR_ZYXEL
)
608 return ZYNOS_VENDOR_ID_ZYXEL
;
610 /* TODO: there are no known ADM5120 based boards from other vendors */
611 if CHECK_VENDOR(ZYNOS_VENDOR_DLINK
)
612 return ZYNOS_VENDOR_ID_DLINK
;
614 if CHECK_VENDOR(ZYNOS_VENDOR_LUCENT
)
615 return ZYNOS_VENDOR_ID_LUCENT
;
617 if CHECK_VENDOR(ZYNOS_VENDOR_NETGEAR
)
618 return ZYNOS_VENDOR_ID_NETGEAR
;
621 return ZYNOS_VENDOR_ID_OTHER
;
624 static inline u16
zynos_get_board_id(struct zynos_board_info
*info
)
626 return read_be16(&info
->board_id
);
629 static inline u32
zynos_get_bootext_addr(struct zynos_board_info
*info
)
631 return read_be32(&info
->bootext_addr
);
635 #define ZYNOS_INFO_ADDR KSEG1ADDR(ADM5120_SRAM0_BASE+0x3F90)
636 #define ZYNOS_HDBG_ADDR KSEG1ADDR(ADM5120_SRAM0_BASE+0x4000)
637 #define BOOTEXT_ADDR_MIN KSEG1ADDR(ADM5120_SRAM0_BASE)
638 #define BOOTEXT_ADDR_MAX (BOOTEXT_ADDR_MIN + (2*1024*1024))
640 static unsigned long __init
zynos_detect_board(void)
642 struct zynos_board_info
*info
;
643 struct zynos_board
*board
;
644 unsigned int vendor_id
;
649 ret
= MACH_ADM5120_UNKNOWN
;
650 /* check presence of the dbgarea */
651 if (zynos_dbgarea_present((u8
*)ZYNOS_HDBG_ADDR
) == 0)
654 info
= (struct zynos_board_info
*)(ZYNOS_INFO_ADDR
);
656 /* check for a valid BootExt address */
657 t
= zynos_get_bootext_addr(info
);
658 if ((t
< BOOTEXT_ADDR_MIN
) || (t
> BOOTEXT_ADDR_MAX
))
661 vendor_id
= zynos_get_vendor_id(info
);
662 board_id
= zynos_get_board_id(info
);
664 for (board
= zynos_boards
; board
->mach_type
!= MACH_ADM5120_UNKNOWN
;
666 if ((board
->vendor_id
== vendor_id
) &&
667 (board
->board_id
== board_id
)) {
668 ret
= board
->mach_type
;
673 /* assume Bootbase as the boot-loader */
674 adm5120_boot_loader
= BOOT_LOADER_BOOTBASE
;
681 * U-Boot based boards
683 static int __init
uboot_present(void)
685 /* FIXME: not yet implemented */
689 static unsigned long __init
uboot_detect_board(void)
691 /* FIXME: not yet implemented */
692 return MACH_ADM5120_UNKNOWN
;
695 static void __init
adm5120_detect_board(void)
697 struct adm5120_board
*board
;
700 adm5120_boot_loader
= BOOT_LOADER_UNKNOWN
;
702 /* Try to detect board type without bootloader */
703 t
= routerboot_detect_board();
705 if (t
== MACH_ADM5120_UNKNOWN
)
706 t
= zynos_detect_board();
708 if (t
== MACH_ADM5120_UNKNOWN
)
709 t
= myloader_detect_board();
711 /* Try to detect bootloader type */
713 adm5120_boot_loader
= BOOT_LOADER_CFE
;
714 if (t
== MACH_ADM5120_UNKNOWN
)
715 t
= cfe_detect_board();
716 } else if (uboot_present()) {
717 adm5120_boot_loader
= BOOT_LOADER_UBOOT
;
718 if (t
== MACH_ADM5120_UNKNOWN
)
719 t
= uboot_detect_board();
722 for (board
= adm5120_boards
; board
->mach_type
!= MACH_ADM5120_UNKNOWN
;
724 if (board
->mach_type
== t
)
728 memcpy(&adm5120_board
, board
, sizeof(adm5120_board
));
732 * CPU settings detection
734 #define CODE_GET_PC(c) ((c) & CODE_PC_MASK)
735 #define CODE_GET_REV(c) (((c) >> CODE_REV_SHIFT) & CODE_REV_MASK)
736 #define CODE_GET_PK(c) (((c) >> CODE_PK_SHIFT) & CODE_PK_MASK)
737 #define CODE_GET_CLKS(c) (((c) >> CODE_CLKS_SHIFT) & CODE_CLKS_MASK)
738 #define CODE_GET_NAB(c) (((c) & CODE_NAB) != 0)
740 static void __init
adm5120_detect_cpuinfo(void)
745 code
= *(u32
*)KSEG1ADDR(ADM5120_SWITCH_BASE
+SWITCH_REG_CODE
);
747 adm5120_product_code
= CODE_GET_PC(code
);
748 adm5120_revision
= CODE_GET_REV(code
);
749 adm5120_package
= (CODE_GET_PK(code
) == CODE_PK_BGA
) ?
750 ADM5120_PACKAGE_BGA
: ADM5120_PACKAGE_PQFP
;
751 adm5120_nand_boot
= CODE_GET_NAB(code
);
753 clks
= CODE_GET_CLKS(code
);
754 adm5120_speed
= ADM5120_SPEED_175
;
756 adm5120_speed
+= 25000000;
758 adm5120_speed
+= 50000000;
761 void __init
adm5120_info_show(void)
763 /* FIXME: move this somewhere else */
764 printk("ADM%04X%s revision %d, running at %ldMHz\n",
765 adm5120_product_code
,
766 (adm5120_package
== ADM5120_PACKAGE_BGA
) ? "" : "P",
767 adm5120_revision
, (adm5120_speed
/ 1000000)
769 printk("Boot loader is: %s\n", boot_loader_names
[adm5120_boot_loader
]);
770 printk("Booted from : %s flash\n", adm5120_nand_boot
? "NAND":"NOR");
771 printk("Board is : %s\n", adm5120_board_name());
774 void __init
adm5120_info_init(void)
776 adm5120_detect_cpuinfo();
777 adm5120_detect_board();