2 * Thomas Horsten <thh@lasat.com>
3 * Copyright (C) 2000 LASAT Networks A/S.
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.
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
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.
18 * Routines specific to the LASAT boards
20 #include <linux/types.h>
21 #include <linux/crc32.h>
22 #include <asm/lasat/lasat.h>
23 #include <linux/kernel.h>
24 #include <linux/string.h>
25 #include <linux/ctype.h>
26 #include <asm/bootinfo.h>
27 #include <asm/addrspace.h>
29 /* New model description table */
30 #include "lasat_models.h"
32 #define EEPROM_CRC(data, len) (~0 ^ crc32(~0, data, len))
34 struct lasat_info lasat_board_info;
36 void update_bcastaddr(void);
38 int EEPROMRead(unsigned int pos, unsigned char *data, int len)
43 *data++ = at93c_read(pos++);
47 int EEPROMWrite(unsigned int pos, unsigned char *data, int len)
52 at93c_write(pos++, *data++);
57 static void init_flash_sizes(void)
60 unsigned long *lb = lasat_board_info.li_flashpart_base;
61 unsigned long *ls = lasat_board_info.li_flashpart_size;
63 ls[LASAT_MTD_BOOTLOADER] = 0x40000;
64 ls[LASAT_MTD_SERVICE] = 0xC0000;
65 ls[LASAT_MTD_NORMAL] = 0x100000;
67 if (mips_machtype == MACH_LASAT_100) {
68 lasat_board_info.li_flash_base = 0x1e000000;
70 lb[LASAT_MTD_BOOTLOADER] = 0x1e400000;
72 if (lasat_board_info.li_flash_size > 0x200000) {
73 ls[LASAT_MTD_CONFIG] = 0x100000;
74 ls[LASAT_MTD_FS] = 0x500000;
77 lasat_board_info.li_flash_base = 0x10000000;
79 if (lasat_board_info.li_flash_size < 0x1000000) {
80 lb[LASAT_MTD_BOOTLOADER] = 0x10000000;
81 ls[LASAT_MTD_CONFIG] = 0x100000;
82 if (lasat_board_info.li_flash_size >= 0x400000) {
83 ls[LASAT_MTD_FS] = lasat_board_info.li_flash_size - 0x300000;
88 for (i = 1; i < LASAT_MTD_LAST; i++)
89 lb[i] = lb[i-1] + ls[i-1];
92 int lasat_init_board_info(void)
96 unsigned long cfg0, cfg1;
97 const product_info_t *ppi;
98 int i_n_base_models = N_BASE_MODELS;
99 const char * const * i_txt_base_models = txt_base_models;
100 int i_n_prids = N_PRIDS;
102 memset(&lasat_board_info, 0, sizeof(lasat_board_info));
104 /* First read the EEPROM info */
105 EEPROMRead(0, (unsigned char *)&lasat_board_info.li_eeprom_info,
106 sizeof(struct lasat_eeprom_struct));
109 crc = EEPROM_CRC((unsigned char *)(&lasat_board_info.li_eeprom_info),
110 sizeof(struct lasat_eeprom_struct) - 4);
112 if (crc != lasat_board_info.li_eeprom_info.crc32) {
113 prom_printf("WARNING...\nWARNING...\nEEPROM CRC does not match calculated, attempting to soldier on...\n");
116 if (lasat_board_info.li_eeprom_info.version != LASAT_EEPROM_VERSION)
118 prom_printf("WARNING...\nWARNING...\nEEPROM version %d, wanted version %d, attempting to soldier on...\n",
119 (unsigned int)lasat_board_info.li_eeprom_info.version,
120 LASAT_EEPROM_VERSION);
123 cfg0 = lasat_board_info.li_eeprom_info.cfg[0];
124 cfg1 = lasat_board_info.li_eeprom_info.cfg[1];
126 if ( LASAT_W0_DSCTYPE(cfg0) != 1) {
127 prom_printf("WARNING...\nWARNING...\nInvalid configuration read from EEPROM, attempting to soldier on...");
129 /* We have a valid configuration */
131 switch (LASAT_W0_SDRAMBANKSZ(cfg0)) {
133 lasat_board_info.li_memsize = 0x0800000;
136 lasat_board_info.li_memsize = 0x1000000;
139 lasat_board_info.li_memsize = 0x2000000;
142 lasat_board_info.li_memsize = 0x4000000;
145 lasat_board_info.li_memsize = 0x8000000;
148 lasat_board_info.li_memsize = 0;
151 switch (LASAT_W0_SDRAMBANKS(cfg0)) {
155 lasat_board_info.li_memsize *= 2;
161 switch (LASAT_W0_BUSSPEED(cfg0)) {
163 lasat_board_info.li_bus_hz = 60000000;
166 lasat_board_info.li_bus_hz = 66000000;
169 lasat_board_info.li_bus_hz = 66666667;
172 lasat_board_info.li_bus_hz = 80000000;
175 lasat_board_info.li_bus_hz = 83333333;
178 lasat_board_info.li_bus_hz = 100000000;
182 switch (LASAT_W0_CPUCLK(cfg0)) {
184 lasat_board_info.li_cpu_hz =
185 lasat_board_info.li_bus_hz;
188 lasat_board_info.li_cpu_hz =
189 lasat_board_info.li_bus_hz +
190 (lasat_board_info.li_bus_hz >> 1);
193 lasat_board_info.li_cpu_hz =
194 lasat_board_info.li_bus_hz +
195 lasat_board_info.li_bus_hz;
198 lasat_board_info.li_cpu_hz =
199 lasat_board_info.li_bus_hz +
200 lasat_board_info.li_bus_hz +
201 (lasat_board_info.li_bus_hz >> 1);
204 lasat_board_info.li_cpu_hz =
205 lasat_board_info.li_bus_hz +
206 lasat_board_info.li_bus_hz +
207 lasat_board_info.li_bus_hz;
212 switch (LASAT_W1_FLASHSIZE(cfg1)) {
214 lasat_board_info.li_flash_size = 0x200000;
217 lasat_board_info.li_flash_size = 0x400000;
220 lasat_board_info.li_flash_size = 0x800000;
223 lasat_board_info.li_flash_size = 0x1000000;
226 lasat_board_info.li_flash_size = 0x2000000;
232 lasat_board_info.li_bmid = LASAT_W0_BMID(cfg0);
233 lasat_board_info.li_prid = lasat_board_info.li_eeprom_info.prid;
234 if (lasat_board_info.li_prid == 0xffff || lasat_board_info.li_prid == 0)
235 lasat_board_info.li_prid = lasat_board_info.li_bmid;
237 /* Base model stuff */
238 if (lasat_board_info.li_bmid > i_n_base_models)
239 lasat_board_info.li_bmid = i_n_base_models;
240 strcpy(lasat_board_info.li_bmstr, i_txt_base_models[lasat_board_info.li_bmid]);
242 /* Product ID dependent values */
243 c = lasat_board_info.li_prid;
244 if (c >= i_n_prids) {
245 strcpy(lasat_board_info.li_namestr, "Unknown Model");
246 strcpy(lasat_board_info.li_typestr, "Unknown Type");
248 ppi = &vendor_info_table[0].vi_product_info[c];
249 strcpy(lasat_board_info.li_namestr, ppi->pi_name);
251 strcpy(lasat_board_info.li_typestr, ppi->pi_type);
253 sprintf(lasat_board_info.li_typestr, "%d",10*c);
256 #if defined(CONFIG_INET) && defined(CONFIG_SYSCTL)
263 void lasat_write_eeprom_info(void)
267 /* Generate the CRC */
268 crc = EEPROM_CRC((unsigned char *)(&lasat_board_info.li_eeprom_info),
269 sizeof(struct lasat_eeprom_struct) - 4);
270 lasat_board_info.li_eeprom_info.crc32 = crc;
272 /* Write the EEPROM info */
273 EEPROMWrite(0, (unsigned char *)&lasat_board_info.li_eeprom_info,
274 sizeof(struct lasat_eeprom_struct));