4 * ZyXEL's Bootbase specific prom routines
6 * Copyright (C) 2007 OpenWrt.org
7 * Copyright (C) 2007 Gabor Juhos <juhosg@freemail.hu>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
25 #include <linux/types.h>
26 #include <linux/autoconf.h>
27 #include <linux/kernel.h>
28 #include <linux/init.h>
29 #include <linux/string.h>
31 #include <asm/bootinfo.h>
32 #include <asm/addrspace.h>
33 #include <asm/byteorder.h>
35 #include <adm5120_defs.h>
36 #include <prom/zynos.h>
37 #include "prom_read.h"
39 #define ZYNOS_INFO_ADDR KSEG1ADDR(ADM5120_SRAM0_BASE+0x3F90)
40 #define ZYNOS_HDBG_ADDR KSEG1ADDR(ADM5120_SRAM0_BASE+0x4000)
41 #define BOOTEXT_ADDR_MIN KSEG1ADDR(ADM5120_SRAM0_BASE)
42 #define BOOTEXT_ADDR_MAX (BOOTEXT_ADDR_MIN + (2*1024*1024))
44 static int bootbase_found
= 0;
45 static struct zynos_board_info
*board_info
;
47 struct bootbase_info bootbase_info
;
49 static inline int bootbase_dbgarea_present(u8
*data
)
53 t
= prom_read_be32(data
+5);
54 if (t
!= ZYNOS_MAGIC_DBGAREA1
)
57 t
= prom_read_be32(data
+9);
58 if (t
!= ZYNOS_MAGIC_DBGAREA2
)
64 static inline u32
bootbase_get_bootext_addr(void)
66 return prom_read_be32(&board_info
->bootext_addr
);
69 static inline u16
bootbase_get_vendor_id(void)
71 #define CHECK_VENDOR(n) (strnicmp(board_info->vendor,(n),strlen(n)) == 0)
72 unsigned char vendor
[ZYNOS_NAME_LEN
];
75 for (i
=0; i
<ZYNOS_NAME_LEN
; i
++)
76 vendor
[i
]=board_info
->vendor
[i
];
78 if CHECK_VENDOR(ZYNOS_VENDOR_ZYXEL
)
79 return ZYNOS_VENDOR_ID_ZYXEL
;
81 if CHECK_VENDOR(ZYNOS_VENDOR_DLINK
)
82 return ZYNOS_VENDOR_ID_DLINK
;
84 if CHECK_VENDOR(ZYNOS_VENDOR_LUCENT
)
85 return ZYNOS_VENDOR_ID_LUCENT
;
87 if CHECK_VENDOR(ZYNOS_VENDOR_NETGEAR
)
88 return ZYNOS_VENDOR_ID_NETGEAR
;
90 return ZYNOS_VENDOR_ID_OTHER
;
93 static inline u16
bootbase_get_board_id(void)
95 return prom_read_be16(&board_info
->board_id
);
98 int __init
bootbase_present(void)
105 /* check presence of the dbgarea */
106 if (bootbase_dbgarea_present((u8
*)ZYNOS_HDBG_ADDR
) == 0)
109 board_info
= (struct zynos_board_info
*)(ZYNOS_INFO_ADDR
);
111 /* check for a valid BootExt address */
112 t
= bootbase_get_bootext_addr();
113 if ((t
< BOOTEXT_ADDR_MIN
) || (t
> BOOTEXT_ADDR_MAX
))
116 bootbase_info
.vendor_id
= bootbase_get_vendor_id();
117 bootbase_info
.board_id
= bootbase_get_board_id();
122 return bootbase_found
;