diff options
Diffstat (limited to 'arch/mips/lasat/lasat_board.c')
-rw-r--r-- | arch/mips/lasat/lasat_board.c | 277 |
1 files changed, 277 insertions, 0 deletions
diff --git a/arch/mips/lasat/lasat_board.c b/arch/mips/lasat/lasat_board.c new file mode 100644 index 000000000000..8c784bcf1111 --- /dev/null +++ b/arch/mips/lasat/lasat_board.c | |||
@@ -0,0 +1,277 @@ | |||
1 | /* | ||
2 | * Thomas Horsten <thh@lasat.com> | ||
3 | * Copyright (C) 2000 LASAT Networks A/S. | ||
4 | * | ||
5 | * This program is free software; you can distribute it and/or modify it | ||
6 | * under the terms of the GNU General Public License (Version 2) as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
12 | * for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License along | ||
15 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
16 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. | ||
17 | * | ||
18 | * Routines specific to the LASAT boards | ||
19 | */ | ||
20 | #include <linux/config.h> | ||
21 | #include <linux/types.h> | ||
22 | #include <linux/crc32.h> | ||
23 | #include <asm/lasat/lasat.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/string.h> | ||
26 | #include <linux/ctype.h> | ||
27 | #include <asm/bootinfo.h> | ||
28 | #include <asm/addrspace.h> | ||
29 | #include "at93c.h" | ||
30 | /* New model description table */ | ||
31 | #include "lasat_models.h" | ||
32 | |||
33 | #define EEPROM_CRC(data, len) (~0 ^ crc32(~0, data, len)) | ||
34 | |||
35 | struct lasat_info lasat_board_info; | ||
36 | |||
37 | void update_bcastaddr(void); | ||
38 | |||
39 | int EEPROMRead(unsigned int pos, unsigned char *data, int len) | ||
40 | { | ||
41 | int i; | ||
42 | |||
43 | for (i=0; i<len; i++) | ||
44 | *data++ = at93c_read(pos++); | ||
45 | |||
46 | return 0; | ||
47 | } | ||
48 | int EEPROMWrite(unsigned int pos, unsigned char *data, int len) | ||
49 | { | ||
50 | int i; | ||
51 | |||
52 | for (i=0; i<len; i++) | ||
53 | at93c_write(pos++, *data++); | ||
54 | |||
55 | return 0; | ||
56 | } | ||
57 | |||
58 | static void init_flash_sizes(void) | ||
59 | { | ||
60 | int i; | ||
61 | unsigned long *lb = lasat_board_info.li_flashpart_base; | ||
62 | unsigned long *ls = lasat_board_info.li_flashpart_size; | ||
63 | |||
64 | ls[LASAT_MTD_BOOTLOADER] = 0x40000; | ||
65 | ls[LASAT_MTD_SERVICE] = 0xC0000; | ||
66 | ls[LASAT_MTD_NORMAL] = 0x100000; | ||
67 | |||
68 | if (mips_machtype == MACH_LASAT_100) { | ||
69 | lasat_board_info.li_flash_base = 0x1e000000; | ||
70 | |||
71 | lb[LASAT_MTD_BOOTLOADER] = 0x1e400000; | ||
72 | |||
73 | if (lasat_board_info.li_flash_size > 0x200000) { | ||
74 | ls[LASAT_MTD_CONFIG] = 0x100000; | ||
75 | ls[LASAT_MTD_FS] = 0x500000; | ||
76 | } | ||
77 | } else { | ||
78 | lasat_board_info.li_flash_base = 0x10000000; | ||
79 | |||
80 | if (lasat_board_info.li_flash_size < 0x1000000) { | ||
81 | lb[LASAT_MTD_BOOTLOADER] = 0x10000000; | ||
82 | ls[LASAT_MTD_CONFIG] = 0x100000; | ||
83 | if (lasat_board_info.li_flash_size >= 0x400000) { | ||
84 | ls[LASAT_MTD_FS] = lasat_board_info.li_flash_size - 0x300000; | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | |||
89 | for (i = 1; i < LASAT_MTD_LAST; i++) | ||
90 | lb[i] = lb[i-1] + ls[i-1]; | ||
91 | } | ||
92 | |||
93 | int lasat_init_board_info(void) | ||
94 | { | ||
95 | int c; | ||
96 | unsigned long crc; | ||
97 | unsigned long cfg0, cfg1; | ||
98 | const product_info_t *ppi; | ||
99 | int i_n_base_models = N_BASE_MODELS; | ||
100 | const char * const * i_txt_base_models = txt_base_models; | ||
101 | int i_n_prids = N_PRIDS; | ||
102 | |||
103 | memset(&lasat_board_info, 0, sizeof(lasat_board_info)); | ||
104 | |||
105 | /* First read the EEPROM info */ | ||
106 | EEPROMRead(0, (unsigned char *)&lasat_board_info.li_eeprom_info, | ||
107 | sizeof(struct lasat_eeprom_struct)); | ||
108 | |||
109 | /* Check the CRC */ | ||
110 | crc = EEPROM_CRC((unsigned char *)(&lasat_board_info.li_eeprom_info), | ||
111 | sizeof(struct lasat_eeprom_struct) - 4); | ||
112 | |||
113 | if (crc != lasat_board_info.li_eeprom_info.crc32) { | ||
114 | prom_printf("WARNING...\nWARNING...\nEEPROM CRC does not match calculated, attempting to soldier on...\n"); | ||
115 | } | ||
116 | |||
117 | if (lasat_board_info.li_eeprom_info.version != LASAT_EEPROM_VERSION) | ||
118 | { | ||
119 | prom_printf("WARNING...\nWARNING...\nEEPROM version %d, wanted version %d, attempting to soldier on...\n", | ||
120 | (unsigned int)lasat_board_info.li_eeprom_info.version, | ||
121 | LASAT_EEPROM_VERSION); | ||
122 | } | ||
123 | |||
124 | cfg0 = lasat_board_info.li_eeprom_info.cfg[0]; | ||
125 | cfg1 = lasat_board_info.li_eeprom_info.cfg[1]; | ||
126 | |||
127 | if ( LASAT_W0_DSCTYPE(cfg0) != 1) { | ||
128 | prom_printf("WARNING...\nWARNING...\nInvalid configuration read from EEPROM, attempting to soldier on..."); | ||
129 | } | ||
130 | /* We have a valid configuration */ | ||
131 | |||
132 | switch (LASAT_W0_SDRAMBANKSZ(cfg0)) { | ||
133 | case 0: | ||
134 | lasat_board_info.li_memsize = 0x0800000; | ||
135 | break; | ||
136 | case 1: | ||
137 | lasat_board_info.li_memsize = 0x1000000; | ||
138 | break; | ||
139 | case 2: | ||
140 | lasat_board_info.li_memsize = 0x2000000; | ||
141 | break; | ||
142 | case 3: | ||
143 | lasat_board_info.li_memsize = 0x4000000; | ||
144 | break; | ||
145 | case 4: | ||
146 | lasat_board_info.li_memsize = 0x8000000; | ||
147 | break; | ||
148 | default: | ||
149 | lasat_board_info.li_memsize = 0; | ||
150 | } | ||
151 | |||
152 | switch (LASAT_W0_SDRAMBANKS(cfg0)) { | ||
153 | case 0: | ||
154 | break; | ||
155 | case 1: | ||
156 | lasat_board_info.li_memsize *= 2; | ||
157 | break; | ||
158 | default: | ||
159 | break; | ||
160 | } | ||
161 | |||
162 | switch (LASAT_W0_BUSSPEED(cfg0)) { | ||
163 | case 0x0: | ||
164 | lasat_board_info.li_bus_hz = 60000000; | ||
165 | break; | ||
166 | case 0x1: | ||
167 | lasat_board_info.li_bus_hz = 66000000; | ||
168 | break; | ||
169 | case 0x2: | ||
170 | lasat_board_info.li_bus_hz = 66666667; | ||
171 | break; | ||
172 | case 0x3: | ||
173 | lasat_board_info.li_bus_hz = 80000000; | ||
174 | break; | ||
175 | case 0x4: | ||
176 | lasat_board_info.li_bus_hz = 83333333; | ||
177 | break; | ||
178 | case 0x5: | ||
179 | lasat_board_info.li_bus_hz = 100000000; | ||
180 | break; | ||
181 | } | ||
182 | |||
183 | switch (LASAT_W0_CPUCLK(cfg0)) { | ||
184 | case 0x0: | ||
185 | lasat_board_info.li_cpu_hz = | ||
186 | lasat_board_info.li_bus_hz; | ||
187 | break; | ||
188 | case 0x1: | ||
189 | lasat_board_info.li_cpu_hz = | ||
190 | lasat_board_info.li_bus_hz + | ||
191 | (lasat_board_info.li_bus_hz >> 1); | ||
192 | break; | ||
193 | case 0x2: | ||
194 | lasat_board_info.li_cpu_hz = | ||
195 | lasat_board_info.li_bus_hz + | ||
196 | lasat_board_info.li_bus_hz; | ||
197 | break; | ||
198 | case 0x3: | ||
199 | lasat_board_info.li_cpu_hz = | ||
200 | lasat_board_info.li_bus_hz + | ||
201 | lasat_board_info.li_bus_hz + | ||
202 | (lasat_board_info.li_bus_hz >> 1); | ||
203 | break; | ||
204 | case 0x4: | ||
205 | lasat_board_info.li_cpu_hz = | ||
206 | lasat_board_info.li_bus_hz + | ||
207 | lasat_board_info.li_bus_hz + | ||
208 | lasat_board_info.li_bus_hz; | ||
209 | break; | ||
210 | } | ||
211 | |||
212 | /* Flash size */ | ||
213 | switch (LASAT_W1_FLASHSIZE(cfg1)) { | ||
214 | case 0: | ||
215 | lasat_board_info.li_flash_size = 0x200000; | ||
216 | break; | ||
217 | case 1: | ||
218 | lasat_board_info.li_flash_size = 0x400000; | ||
219 | break; | ||
220 | case 2: | ||
221 | lasat_board_info.li_flash_size = 0x800000; | ||
222 | break; | ||
223 | case 3: | ||
224 | lasat_board_info.li_flash_size = 0x1000000; | ||
225 | break; | ||
226 | case 4: | ||
227 | lasat_board_info.li_flash_size = 0x2000000; | ||
228 | break; | ||
229 | } | ||
230 | |||
231 | init_flash_sizes(); | ||
232 | |||
233 | lasat_board_info.li_bmid = LASAT_W0_BMID(cfg0); | ||
234 | lasat_board_info.li_prid = lasat_board_info.li_eeprom_info.prid; | ||
235 | if (lasat_board_info.li_prid == 0xffff || lasat_board_info.li_prid == 0) | ||
236 | lasat_board_info.li_prid = lasat_board_info.li_bmid; | ||
237 | |||
238 | /* Base model stuff */ | ||
239 | if (lasat_board_info.li_bmid > i_n_base_models) | ||
240 | lasat_board_info.li_bmid = i_n_base_models; | ||
241 | strcpy(lasat_board_info.li_bmstr, i_txt_base_models[lasat_board_info.li_bmid]); | ||
242 | |||
243 | /* Product ID dependent values */ | ||
244 | c = lasat_board_info.li_prid; | ||
245 | if (c >= i_n_prids) { | ||
246 | strcpy(lasat_board_info.li_namestr, "Unknown Model"); | ||
247 | strcpy(lasat_board_info.li_typestr, "Unknown Type"); | ||
248 | } else { | ||
249 | ppi = &vendor_info_table[0].vi_product_info[c]; | ||
250 | strcpy(lasat_board_info.li_namestr, ppi->pi_name); | ||
251 | if (ppi->pi_type) | ||
252 | strcpy(lasat_board_info.li_typestr, ppi->pi_type); | ||
253 | else | ||
254 | sprintf(lasat_board_info.li_typestr, "%d",10*c); | ||
255 | } | ||
256 | |||
257 | #if defined(CONFIG_INET) && defined(CONFIG_SYSCTL) | ||
258 | update_bcastaddr(); | ||
259 | #endif | ||
260 | |||
261 | return 0; | ||
262 | } | ||
263 | |||
264 | void lasat_write_eeprom_info(void) | ||
265 | { | ||
266 | unsigned long crc; | ||
267 | |||
268 | /* Generate the CRC */ | ||
269 | crc = EEPROM_CRC((unsigned char *)(&lasat_board_info.li_eeprom_info), | ||
270 | sizeof(struct lasat_eeprom_struct) - 4); | ||
271 | lasat_board_info.li_eeprom_info.crc32 = crc; | ||
272 | |||
273 | /* Write the EEPROM info */ | ||
274 | EEPROMWrite(0, (unsigned char *)&lasat_board_info.li_eeprom_info, | ||
275 | sizeof(struct lasat_eeprom_struct)); | ||
276 | } | ||
277 | |||