[adm5120] coding style fixes
[openwrt-10.03/.git] / target / linux / adm5120 / files / arch / mips / adm5120 / prom / bootbase.c
1 /*
2  *  $Id$
3  *
4  *  ZyXEL's Bootbase specific prom routines
5  *
6  *  Copyright (C) 2007 OpenWrt.org
7  *  Copyright (C) 2007 Gabor Juhos <juhosg at openwrt.org>
8  *
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.
13  *
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.
18  *
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.
23  */
24
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>
30
31 #include <asm/bootinfo.h>
32 #include <asm/addrspace.h>
33 #include <asm/byteorder.h>
34
35 #include <adm5120_defs.h>
36 #include <prom/zynos.h>
37 #include "prom_read.h"
38
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))
43
44 static int bootbase_found;
45 static struct zynos_board_info *board_info;
46
47 struct bootbase_info bootbase_info;
48
49 static inline int bootbase_dbgarea_present(u8 *data)
50 {
51         u32 t;
52
53         t = prom_read_be32(data+5);
54         if (t != ZYNOS_MAGIC_DBGAREA1)
55                 return 0;
56
57         t = prom_read_be32(data+9);
58         if (t != ZYNOS_MAGIC_DBGAREA2)
59                 return 0;
60
61         return 1;
62 }
63
64 static inline u32 bootbase_get_bootext_addr(void)
65 {
66         return prom_read_be32(&board_info->bootext_addr);
67 }
68
69 static inline u16 bootbase_get_vendor_id(void)
70 {
71 #define CHECK_VENDOR(n) (strnicmp(board_info->vendor, (n), strlen(n)) == 0)
72         unsigned char vendor[ZYNOS_NAME_LEN];
73         int i;
74
75         for (i = 0; i < ZYNOS_NAME_LEN; i++)
76                 vendor[i] = board_info->vendor[i];
77
78         if CHECK_VENDOR(ZYNOS_VENDOR_ZYXEL)
79                 return ZYNOS_VENDOR_ID_ZYXEL;
80
81         if CHECK_VENDOR(ZYNOS_VENDOR_DLINK)
82                 return ZYNOS_VENDOR_ID_DLINK;
83
84         if CHECK_VENDOR(ZYNOS_VENDOR_LUCENT)
85                 return ZYNOS_VENDOR_ID_LUCENT;
86
87         if CHECK_VENDOR(ZYNOS_VENDOR_NETGEAR)
88                 return ZYNOS_VENDOR_ID_NETGEAR;
89
90         return ZYNOS_VENDOR_ID_OTHER;
91 }
92
93 static inline u16 bootbase_get_board_id(void)
94 {
95         return prom_read_be16(&board_info->board_id);
96 }
97
98 int __init bootbase_present(void)
99 {
100         u32     t;
101
102         if (bootbase_found)
103                 goto out;
104
105         /* check presence of the dbgarea */
106         if (bootbase_dbgarea_present((u8 *)ZYNOS_HDBG_ADDR) == 0)
107                 goto out;
108
109         board_info = (struct zynos_board_info *)(ZYNOS_INFO_ADDR);
110
111         /* check for a valid BootExt address */
112         t = bootbase_get_bootext_addr();
113         if ((t < BOOTEXT_ADDR_MIN) || (t > BOOTEXT_ADDR_MAX))
114                 goto out;
115
116         bootbase_info.vendor_id = bootbase_get_vendor_id();
117         bootbase_info.board_id = bootbase_get_board_id();
118
119         bootbase_found = 1;
120
121 out:
122         return bootbase_found;
123 }
124