4 * ZyXEL's Bootbase specific prom routines
6 * Copyright (C) 2007 OpenWrt.org
7 * Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
15 #include <linux/types.h>
16 #include <linux/autoconf.h>
17 #include <linux/kernel.h>
18 #include <linux/init.h>
19 #include <linux/string.h>
21 #include <asm/bootinfo.h>
22 #include <asm/addrspace.h>
23 #include <asm/byteorder.h>
25 #include <adm5120_defs.h>
26 #include <prom/zynos.h>
27 #include "prom_read.h"
29 #define ZYNOS_INFO_ADDR KSEG1ADDR(ADM5120_SRAM0_BASE+0x3F90)
30 #define ZYNOS_HDBG_ADDR KSEG1ADDR(ADM5120_SRAM0_BASE+0x4000)
31 #define BOOTEXT_ADDR_MIN KSEG1ADDR(ADM5120_SRAM0_BASE)
32 #define BOOTEXT_ADDR_MAX (BOOTEXT_ADDR_MIN + (2*1024*1024))
34 static int bootbase_found
;
35 static struct zynos_board_info
*board_info
;
37 struct bootbase_info bootbase_info
;
39 static inline int bootbase_dbgarea_present(u8
*data
)
43 t
= prom_read_be32(data
+5);
44 if (t
!= ZYNOS_MAGIC_DBGAREA1
)
47 t
= prom_read_be32(data
+9);
48 if (t
!= ZYNOS_MAGIC_DBGAREA2
)
54 static inline u32
bootbase_get_bootext_addr(void)
56 return prom_read_be32(&board_info
->bootext_addr
);
59 static inline u16
bootbase_get_vendor_id(void)
61 #define CHECK_VENDOR(n) (strnicmp(board_info->vendor, (n), strlen(n)) == 0)
62 unsigned char vendor
[ZYNOS_NAME_LEN
];
65 for (i
= 0; i
< ZYNOS_NAME_LEN
; i
++)
66 vendor
[i
] = board_info
->vendor
[i
];
68 if CHECK_VENDOR(ZYNOS_VENDOR_ZYXEL
)
69 return ZYNOS_VENDOR_ID_ZYXEL
;
71 if CHECK_VENDOR(ZYNOS_VENDOR_DLINK
)
72 return ZYNOS_VENDOR_ID_DLINK
;
74 if CHECK_VENDOR(ZYNOS_VENDOR_LUCENT
)
75 return ZYNOS_VENDOR_ID_LUCENT
;
77 if CHECK_VENDOR(ZYNOS_VENDOR_NETGEAR
)
78 return ZYNOS_VENDOR_ID_NETGEAR
;
80 return ZYNOS_VENDOR_ID_OTHER
;
83 static inline u16
bootbase_get_board_id(void)
85 return prom_read_be16(&board_info
->board_id
);
88 int __init
bootbase_present(void)
95 /* check presence of the dbgarea */
96 if (bootbase_dbgarea_present((u8
*)ZYNOS_HDBG_ADDR
) == 0)
99 board_info
= (struct zynos_board_info
*)(ZYNOS_INFO_ADDR
);
101 /* check for a valid BootExt address */
102 t
= bootbase_get_bootext_addr();
103 if ((t
< BOOTEXT_ADDR_MIN
) || (t
> BOOTEXT_ADDR_MAX
))
106 bootbase_info
.vendor_id
= bootbase_get_vendor_id();
107 bootbase_info
.board_id
= bootbase_get_board_id();
112 return bootbase_found
;