2090cdb9e91e8d8d71868a3d017cc8c917f6013a
[openwrt.git] / target / linux / adm5120 / files-2.6.34 / arch / mips / adm5120 / prom / bootbase.c
1 /*
2 * ZyXEL's Bootbase specific prom routines
3 *
4 * Copyright (C) 2007-2008 Gabor Juhos <juhosg@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 *
10 */
11
12 #include <linux/types.h>
13 #include <generated/autoconf.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/string.h>
17
18 #include <asm/bootinfo.h>
19 #include <asm/addrspace.h>
20 #include <asm/byteorder.h>
21
22 #include <asm/mach-adm5120/adm5120_defs.h>
23 #include <prom/zynos.h>
24 #include "prom_read.h"
25
26 #define ZYNOS_INFO_ADDR KSEG1ADDR(ADM5120_SRAM0_BASE+0x3F90)
27 #define ZYNOS_HDBG_ADDR KSEG1ADDR(ADM5120_SRAM0_BASE+0x4000)
28 #define BOOTEXT_ADDR_MIN KSEG1ADDR(ADM5120_SRAM0_BASE)
29 #define BOOTEXT_ADDR_MAX (BOOTEXT_ADDR_MIN + (2*1024*1024))
30
31 static int bootbase_found;
32 static struct zynos_board_info *board_info;
33
34 struct bootbase_info bootbase_info;
35
36 static inline int bootbase_dbgarea_present(u8 *data)
37 {
38 u32 t;
39
40 t = prom_read_be32(data+5);
41 if (t != ZYNOS_MAGIC_DBGAREA1)
42 return 0;
43
44 t = prom_read_be32(data+9);
45 if (t != ZYNOS_MAGIC_DBGAREA2)
46 return 0;
47
48 return 1;
49 }
50
51 static inline u32 bootbase_get_bootext_addr(void)
52 {
53 return prom_read_be32(&board_info->bootext_addr);
54 }
55
56 static inline void bootbase_get_mac(u8 *mac)
57 {
58 int i;
59
60 for (i = 0; i < 6; i++)
61 mac[i] = board_info->mac[i];
62 }
63
64 static inline u16 bootbase_get_vendor_id(void)
65 {
66 #define CHECK_VENDOR(n) (strnicmp(board_info->vendor, (n), strlen(n)) == 0)
67 unsigned char vendor[ZYNOS_NAME_LEN];
68 int i;
69
70 for (i = 0; i < ZYNOS_NAME_LEN; i++)
71 vendor[i] = board_info->vendor[i];
72
73 if CHECK_VENDOR(ZYNOS_VENDOR_ZYXEL)
74 return ZYNOS_VENDOR_ID_ZYXEL;
75
76 if CHECK_VENDOR(ZYNOS_VENDOR_DLINK)
77 return ZYNOS_VENDOR_ID_DLINK;
78
79 if CHECK_VENDOR(ZYNOS_VENDOR_LUCENT)
80 return ZYNOS_VENDOR_ID_LUCENT;
81
82 if CHECK_VENDOR(ZYNOS_VENDOR_NETGEAR)
83 return ZYNOS_VENDOR_ID_NETGEAR;
84
85 return ZYNOS_VENDOR_ID_OTHER;
86 }
87
88 static inline u16 bootbase_get_board_id(void)
89 {
90 return prom_read_be16(&board_info->board_id);
91 }
92
93 int __init bootbase_present(void)
94 {
95 u32 t;
96
97 if (bootbase_found)
98 goto out;
99
100 /* check presence of the dbgarea */
101 if (bootbase_dbgarea_present((u8 *)ZYNOS_HDBG_ADDR) == 0)
102 goto out;
103
104 board_info = (struct zynos_board_info *)(ZYNOS_INFO_ADDR);
105
106 /* check for a valid BootExt address */
107 t = bootbase_get_bootext_addr();
108 if ((t < BOOTEXT_ADDR_MIN) || (t > BOOTEXT_ADDR_MAX))
109 goto out;
110
111 bootbase_info.vendor_id = bootbase_get_vendor_id();
112 bootbase_info.board_id = bootbase_get_board_id();
113 bootbase_get_mac(bootbase_info.mac);
114
115 bootbase_found = 1;
116
117 out:
118 return bootbase_found;
119 }
120
This page took 0.041175 seconds and 3 git commands to generate.