blob: af85444f485c7c2437e6396034ab0add7dc6ab2d [file] [log] [blame]
wdenk452cfd62002-11-19 11:04:11 +00001/*
2 * (C) Copyright 2002
3 * Hyperion Entertainment, ThomasF@hyperion-entertainment.com
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <pci.h>
26#include <asm/processor.h>
27#include "memio.h"
28#include "articiaS.h"
29#include "smbus.h"
30#include "via686.h"
31
32#undef DEBUG
33
34struct dimm_bank {
35 uint8 used; /* Bank is populated */
36 uint32 rows; /* Number of row addresses */
37 uint32 columns; /* Number of column addresses */
38 uint8 registered; /* SIMM is registered */
39 uint8 ecc; /* SIMM has ecc */
40 uint8 burst_len; /* Supported burst lengths */
41 uint32 cas_lat; /* Supported CAS latencies */
42 uint32 cas_used; /* CAS to use (not set by user) */
43 uint32 trcd; /* RAS to CAS latency */
44 uint32 trp; /* Precharge latency */
45 uint32 tclk_hi; /* SDRAM cycle time (highest CAS latency) */
46 uint32 tclk_2hi; /* SDRAM second highest CAS latency */
47 uint32 size; /* Size of bank in bytes */
48 uint8 auto_refresh; /* Module supports auto refresh */
49 uint32 refresh_time; /* Refresh time (in ns) */
50};
51
52
53/*
54** Based in part on the evb64260 code
55*/
56
57/*
58 * translate ns.ns/10 coding of SPD timing values
59 * into 10 ps unit values
60 */
61static inline unsigned short NS10to10PS (unsigned char spd_byte)
62{
63 unsigned short ns, ns10;
64
65 /* isolate upper nibble */
66 ns = (spd_byte >> 4) & 0x0F;
67 /* isolate lower nibble */
68 ns10 = (spd_byte & 0x0F);
69
70 return (ns * 100 + ns10 * 10);
71}
72
73/*
74 * translate ns coding of SPD timing values
75 * into 10 ps unit values
76 */
77static inline unsigned short NSto10PS (unsigned char spd_byte)
78{
79 return (spd_byte * 100);
80}
81
82
83long detect_sdram (uint8 * rom, int dimmNum, struct dimm_bank *banks)
84{
85 int dimm_address = (dimmNum == 0) ? SM_DIMM0_ADDR : SM_DIMM1_ADDR;
86 uint32 busclock = get_bus_freq (0);
87 uint32 memclock = busclock;
88 uint32 tmemclock = 1000000000 / (memclock / 100);
89 uint32 datawidth;
90
91 if (sm_get_data (rom, dimm_address) == 0) {
92 /* Nothing in slot, make both banks empty */
93 debug ("Slot %d: vacant\n", dimmNum);
94 banks[0].used = 0;
95 banks[1].used = 0;
96 return 0;
97 }
98
99 if (rom[2] != 0x04) {
100 debug ("Slot %d: No SDRAM\n", dimmNum);
101 banks[0].used = 0;
102 banks[1].used = 0;
103 return 0;
104 }
105
106 /* Determine number of banks/rows */
107 if (rom[5] == 1) {
108 banks[0].used = 1;
109 banks[1].used = 0;
110 } else {
111 banks[0].used = 1;
112 banks[1].used = 1;
113 }
114
115 /* Determine number of row addresses */
116 if (rom[3] & 0xf0) {
117 /* Different banks sizes */
118 banks[0].rows = rom[3] & 0x0f;
119 banks[1].rows = (rom[3] & 0xf0) >> 4;
120 } else {
121 /* Equal sized banks */
122 banks[0].rows = rom[3] & 0x0f;
123 banks[1].rows = banks[0].rows;
124 }
125
126 /* Determine number of column addresses */
127 if (rom[4] & 0xf0) {
128 /* Different bank sizes */
129 banks[0].columns = rom[4] & 0x0f;
130 banks[1].columns = (rom[4] & 0xf0) >> 4;
131 } else {
132 banks[0].columns = rom[4] & 0x0f;
133 banks[1].columns = banks[0].columns;
134 }
135
136 /* Check Jedec revision, and modify row/column accordingly */
137 if (rom[62] > 0x10) {
138 if (banks[0].rows <= 3)
139 banks[0].rows += 15;
140 if (banks[1].rows <= 3)
141 banks[1].rows += 15;
142 if (banks[0].columns <= 3)
143 banks[0].columns += 15;
144 if (banks[0].columns <= 3)
145 banks[0].columns += 15;
146 }
147
148 /* Check registered/unregisterd */
149 if (rom[21] & 0x12) {
150 banks[0].registered = 1;
151 banks[1].registered = 1;
152 } else {
153 banks[0].registered = 0;
154 banks[1].registered = 0;
155 }
156
157#ifdef CONFIG_ECC
158 /* Check parity/ECC */
159 banks[0].ecc = (rom[11] == 0x02);
160 banks[1].ecc = (rom[11] == 0x02);
161#endif
162
163 /* Find burst lengths supported */
164 banks[0].burst_len = rom[16] & 0x8f;
165 banks[1].burst_len = rom[16] & 0x8f;
166
167 /* Find possible cas latencies */
168 banks[0].cas_lat = rom[18] & 0x7F;
169 banks[1].cas_lat = rom[18] & 0x7F;
170
171 /* RAS/CAS latency */
172 banks[0].trcd = (NSto10PS (rom[29]) + (tmemclock - 1)) / tmemclock;
173 banks[1].trcd = (NSto10PS (rom[29]) + (tmemclock - 1)) / tmemclock;
174
175 /* Precharge latency */
176 banks[0].trp = (NSto10PS (rom[27]) + (tmemclock - 1)) / tmemclock;
177 banks[1].trp = (NSto10PS (rom[27]) + (tmemclock - 1)) / tmemclock;
178
179 /* highest CAS latency */
180 banks[0].tclk_hi = NS10to10PS (rom[9]);
181 banks[1].tclk_hi = NS10to10PS (rom[9]);
182
183 /* second highest CAS latency */
184 banks[0].tclk_2hi = NS10to10PS (rom[23]);
185 banks[1].tclk_2hi = NS10to10PS (rom[23]);
186
187 /* bank sizes */
188 datawidth = rom[13] & 0x7f;
189 banks[0].size =
190 (1L << (banks[0].rows + banks[0].columns)) *
191 /* FIXME datawidth */ 8 * rom[17];
192 if (rom[13] & 0x80)
193 banks[1].size = 2 * banks[0].size;
194 else
195 banks[1].size = (1L << (banks[1].rows + banks[1].columns)) *
196 /* FIXME datawidth */ 8 * rom[17];
197
198 /* Refresh */
199 if (rom[12] & 0x80) {
200 banks[0].auto_refresh = 1;
201 banks[1].auto_refresh = 1;
202 } else {
203 banks[0].auto_refresh = 0;
204 banks[1].auto_refresh = 0;
205 }
206
207 switch (rom[12] & 0x7f) {
208 case 0:
209 banks[0].refresh_time = (1562500 + (tmemclock - 1)) / tmemclock;
210 banks[1].refresh_time = (1562500 + (tmemclock - 1)) / tmemclock;
211 break;
212 case 1:
213 banks[0].refresh_time = (390600 + (tmemclock - 1)) / tmemclock;
214 banks[1].refresh_time = (390600 + (tmemclock - 1)) / tmemclock;
215 break;
216 case 2:
217 banks[0].refresh_time = (781200 + (tmemclock - 1)) / tmemclock;
218 banks[1].refresh_time = (781200 + (tmemclock - 1)) / tmemclock;
219 break;
220 case 3:
221 banks[0].refresh_time = (3125000 + (tmemclock - 1)) / tmemclock;
222 banks[1].refresh_time = (3125000 + (tmemclock - 1)) / tmemclock;
223 break;
224 case 4:
225 banks[0].refresh_time = (6250000 + (tmemclock - 1)) / tmemclock;
226 banks[1].refresh_time = (6250000 + (tmemclock - 1)) / tmemclock;
227 break;
228 case 5:
229 banks[0].refresh_time = (12500000 + (tmemclock - 1)) / tmemclock;
230 banks[1].refresh_time = (12500000 + (tmemclock - 1)) / tmemclock;
231 break;
232 default:
233 banks[0].refresh_time = 0x100; /* Default of Articia S */
234 banks[1].refresh_time = 0x100;
235 break;
236 }
237
238#ifdef DEBUG
239 printf ("\nInformation for SIMM bank %ld:\n", dimmNum);
240 printf ("Number of banks: %ld\n", banks[0].used + banks[1].used);
241 printf ("Number of row addresses: %ld\n", banks[0].rows);
242 printf ("Number of coumns addresses: %ld\n", banks[0].columns);
243 printf ("SIMM is %sregistered\n",
244 banks[0].registered == 0 ? "not " : "");
245#ifdef CONFIG_ECC
246 printf ("SIMM %s ECC\n",
247 banks[0].ecc == 1 ? "supports" : "doesn't support");
248#endif
249 printf ("Supported burst lenghts: %s %s %s %s %s\n",
250 banks[0].burst_len & 0x08 ? "8" : " ",
251 banks[0].burst_len & 0x04 ? "4" : " ",
252 banks[0].burst_len & 0x02 ? "2" : " ",
253 banks[0].burst_len & 0x01 ? "1" : " ",
254 banks[0].burst_len & 0x80 ? "PAGE" : " ");
255 printf ("Supported CAS latencies: %s %s %s\n",
256 banks[0].cas_lat & 0x04 ? "CAS 3" : " ",
257 banks[0].cas_lat & 0x02 ? "CAS 2" : " ",
258 banks[0].cas_lat & 0x01 ? "CAS 1" : " ");
259 printf ("RAS to CAS latency: %ld\n", banks[0].trcd);
260 printf ("Precharge latency: %ld\n", banks[0].trp);
261 printf ("SDRAM highest CAS latency: %ld\n", banks[0].tclk_hi);
262 printf ("SDRAM 2nd highest CAS latency: %ld\n", banks[0].tclk_2hi);
263 printf ("SDRAM data width: %ld\n", datawidth);
264 printf ("Auto Refresh %ssupported\n",
265 banks[0].auto_refresh ? "" : "not ");
266 printf ("Refresh time: %ld clocks\n", banks[0].refresh_time);
267 if (banks[0].used)
268 printf ("Bank 0 size: %ld MB\n", banks[0].size / 1024 / 1024);
269 if (banks[1].used)
270 printf ("Bank 1 size: %ld MB\n", banks[1].size / 1024 / 1024);
271
272 printf ("\n");
273#endif
274
275 sm_term ();
276 return 1;
277}
278
279void select_cas (struct dimm_bank *banks, uint8 fast)
280{
281 if (!banks[0].used) {
282 banks[0].cas_used = 0;
283 banks[0].cas_used = 0;
284 return;
285 }
286
287 if (fast) {
288 /* Search for fast CAS */
289 uint32 i;
290 uint32 c = 0x01;
291
292 for (i = 1; i < 5; i++) {
293 if (banks[0].cas_lat & c) {
294 banks[0].cas_used = i;
295 banks[1].cas_used = i;
296 debug ("Using CAS %d (fast)\n", i);
297 return;
298 }
299 c <<= 1;
300 }
301
302 /* Default to CAS 3 */
303 banks[0].cas_used = 3;
304 banks[1].cas_used = 3;
305 debug ("Using CAS 3 (fast)\n");
306
307 return;
308 } else {
309 /* Search for slow cas */
310 uint32 i;
311 uint32 c = 0x08;
312
313 for (i = 4; i > 1; i--) {
314 if (banks[0].cas_lat & c) {
315 banks[0].cas_used = i;
316 banks[1].cas_used = i;
317 debug ("Using CAS %d (slow)\n", i);
318 return;
319 }
320 c >>= 1;
321 }
322
323 /* Default to CAS 3 */
324 banks[0].cas_used = 3;
325 banks[1].cas_used = 3;
326 debug ("Using CAS 3 (slow)\n");
327
328 return;
329 }
330
331 banks[0].cas_used = 3;
332 banks[1].cas_used = 3;
333 debug ("Using CAS 3\n");
334
335 return;
336}
337
338uint32 get_reg_setting (uint32 banks, uint32 rows, uint32 columns, uint32 size)
339{
340 uint32 i;
341
342 struct RowColumnSize {
343 uint32 banks;
344 uint32 rows;
345 uint32 columns;
346 uint32 size;
347 uint32 register_value;
348 };
349
350 struct RowColumnSize rcs_map[] = {
351 /* Sbk Radr Cadr MB Value */
352 {1, 11, 8, 8, 0x00840f00},
353 {1, 11, 9, 16, 0x00925f00},
354 {1, 11, 10, 32, 0x00a64f00},
355 {2, 12, 8, 32, 0x00c55f00},
356 {2, 12, 9, 64, 0x00d66f00},
357 {2, 12, 10, 128, 0x00e77f00},
358 {2, 12, 11, 256, 0x00ff8f00},
359 {2, 13, 11, 512, 0x00ff9f00},
360 {0, 0, 0, 0, 0x00000000}
361 };
362
363
364 i = 0;
365
366 while (rcs_map[i].banks != 0) {
367 if (rows == rcs_map[i].rows
368 && columns == rcs_map[i].columns
369 && (size / 1024 / 1024) == rcs_map[i].size)
370 return rcs_map[i].register_value;
371
372 i++;
373 }
374
375 return 0;
376}
377
378uint32 burst_to_len (uint32 support)
379{
380 if (support & 0x80)
381 return 0x7;
382 else if (support & 0x8)
383 return 0x3;
384 else if (support & 0x4)
385 return 0x2;
386 else if (support & 0x2)
387 return 0x1;
388 else if (support & 0x1)
389 return 0x0;
390
391 return 0;
392}
393
394long articiaS_ram_init (void)
395{
396 DECLARE_GLOBAL_DATA_PTR;
397
398 register uint32 i;
399 register uint32 value1;
400 register uint32 value2;
401 uint8 rom[128];
402 uint32 burst_len;
403 uint32 burst_support;
404 uint32 total_ram = 0;
405
406 struct dimm_bank banks[4]; /* FIXME: Move to initram */
407 uint32 busclock = get_bus_freq (0);
408 uint32 memclock = busclock;
409 uint32 reg32;
410 uint32 refresh_clocks;
411 uint8 auto_refresh;
412
413 memset (banks, 0, sizeof (struct dimm_bank) * 4);
414
415 detect_sdram (rom, 0, &banks[0]);
416 detect_sdram (rom, 1, &banks[2]);
417
418 for (i = 0; i < 4; i++) {
419 total_ram = total_ram + (banks[i].used * banks[i].size);
420 }
421
422 pci_write_cfg_long (0, 0, GLOBALINFO0, 0x117430c0);
423 pci_write_cfg_long (0, 0, HBUSACR0, 0x1f0100b0);
424 pci_write_cfg_long (0, 0, SRAM_CR, 0x00f12000); /* Note: Might also try 0x00f10000 (original: 0x00f12000) */
425 pci_write_cfg_byte (0, 0, DRAM_RAS_CTL0, 0x3f);
426 pci_write_cfg_byte (0, 0, DRAM_RAS_CTL1, 0x00); /* was: 0x04); */
427 pci_write_cfg_word (0, 0, DRAM_ECC0, 0x2020); /* was: 0x2400); No ECC yet */
428
429 /* FIXME: Move this stuff to seperate function, like setup_dimm_bank */
430 if (banks[0].used) {
431 value1 = get_reg_setting (banks[0].used + banks[1].used,
432 banks[0].rows, banks[0].columns,
433 banks[0].size);
434 } else {
435 value1 = 0;
436 }
437
438 if (banks[1].used) {
439 value2 = get_reg_setting (banks[0].used + banks[1].used,
440 banks[1].rows, banks[1].columns,
441 banks[1].size);
442 } else {
443 value2 = 0;
444 }
445
446 pci_write_cfg_long (0, 0, DIMM0_B0_SCR0, value1);
447 pci_write_cfg_long (0, 0, DIMM0_B1_SCR0, value2);
448
449 debug ("DIMM0_B0_SCR0 = 0x%08x\n", value1);
450 debug ("DIMM0_B1_SCR0 = 0x%08x\n", value2);
451
452 if (banks[2].used) {
453 value1 = get_reg_setting (banks[2].used + banks[3].used,
454 banks[2].rows, banks[2].columns,
455 banks[2].size);
456 } else {
457 value1 = 0;
458 }
459
460 if (banks[3].used) {
461 value2 = get_reg_setting (banks[2].used + banks[3].used,
462 banks[3].rows, banks[3].columns,
463 banks[3].size);
464 } else {
465 value2 = 0;
466 }
467
468 pci_write_cfg_long (0, 0, DIMM1_B2_SCR0, value1);
469 pci_write_cfg_long (0, 0, DIMM1_B3_SCR0, value2);
470
471 debug ("DIMM0_B2_SCR0 = 0x%08x\n", value1);
472 debug ("DIMM0_B3_SCR0 = 0x%08x\n", value2);
473
474 pci_write_cfg_long (0, 0, DIMM2_B4_SCR0, 0);
475 pci_write_cfg_long (0, 0, DIMM2_B5_SCR0, 0);
476 pci_write_cfg_long (0, 0, DIMM3_B6_SCR0, 0);
477 pci_write_cfg_long (0, 0, DIMM3_B7_SCR0, 0);
478
479 /* Determine timing */
480 select_cas (&banks[0], 0);
481 select_cas (&banks[2], 0);
482
483 /* FIXME: What about write recovery */
484 /* Auto refresh Precharge */
485#if 0
486 reg32 = (0x3 << 13) | (0x7 << 10) | ((banks[0].trp - 2) << 8) |
487 /* Write recovery CAS Latency */
488 (0x1 << 6) | (banks[0].cas_used << 4) |
489 /* RAS/CAS latency */
490 ((banks[0].trcd - 1) << 0);
491
492 reg32 |= ((0x3 << 13) | (0x7 << 10) | ((banks[2].trp - 2) << 8) |
493 (0x1 << 6) | (banks[2].cas_used << 4) |
494 ((banks[2].trcd - 1) << 0)) << 16;
495#else
496 if (100000000 == gd->bus_clk)
497 reg32 = 0x71737173;
498 else
499 reg32 = 0x69736973;
500#endif
501 pci_write_cfg_long (0, 0, DIMM0_TCR0, reg32);
502 debug ("DIMM0_TCR0 = 0x%08x\n", reg32);
503
504 /* Write default in DIMM2/3 (not used on A1) */
505 pci_write_cfg_long (0, 0, DIMM2_TCR0, 0x7d737d73);
506
507
508 /* Determine buffered/unbuffered mode for each SIMM. Uses first bank as reference (second, if present, uses the same) */
509 reg32 = pci_read_cfg_long (0, 0, DRAM_GCR0);
510 reg32 &= 0xFF00FFFF;
511
512#if 0
513 if (banks[0].used && banks[0].registered)
514 reg32 |= 0x1 << 16;
515
516 if (banks[2].used && banks[2].registered)
517 reg32 |= 0x1 << 18;
518#else
519 if (banks[0].registered || banks[2].registered)
520 reg32 |= 0x55 << 16;
521#endif
522 pci_write_cfg_long (0, 0, DRAM_GCR0, reg32);
523 debug ("DRAM_GCR0 = 0x%08x\n", reg32);
524
525 /* Determine refresh */
526 refresh_clocks = 0xffffffff;
527 auto_refresh = 1;
528
529 for (i = 0; i < 4; i++) {
530 if (banks[i].used) {
531 if (banks[i].auto_refresh == 0)
532 auto_refresh = 0;
533 if (banks[i].refresh_time < refresh_clocks)
534 refresh_clocks = banks[i].refresh_time;
535 }
536 }
537
538
539#if 1
540 /* It seems this is suggested by the ArticiaS data book */
541 if (100000000 == gd->bus_clk)
542 refresh_clocks = 1561;
543 else
544 refresh_clocks = 2083;
545#endif
546
547
548 debug ("Refresh set to %ld clocks, auto refresh %s\n",
549 refresh_clocks, auto_refresh ? "on" : "off");
550
551 pci_write_cfg_long (0, 0, DRAM_REFRESH0,
552 (1 << 16) | (1 << 15) | (auto_refresh << 12) |
553 (refresh_clocks));
554 debug ("DRAM_REFRESH0 = 0x%08x\n",
555 (1 << 16) | (1 << 15) | (auto_refresh << 12) |
556 (refresh_clocks));
557
558/* pci_write_cfg_long(0, 0, DRAM_REFRESH0, 0x00019400); */
559
560 /* Set mode registers */
561 /* FIXME: For now, set same burst len for all modules. Dunno if that's necessary */
562 /* Find a common burst len */
563 burst_support = 0xff;
564
565 if (banks[0].used)
566 burst_support = banks[0].burst_len;
567 if (banks[1].used)
568 burst_support = banks[1].burst_len;
569 if (banks[2].used)
570 burst_support = banks[2].burst_len;
571 if (banks[3].used)
572 burst_support = banks[3].burst_len;
573
574 /*
575 ** Mode register:
576 ** Bits Use
577 ** 0-2 Burst len
578 ** 3 Burst type (0 = sequential, 1 = interleave)
579 ** 4-6 CAS latency
580 ** 7-8 Operation mode (0 = default, all others invalid)
581 ** 9 Write burst
582 ** 10-11 Reserved
583 **
584 ** Mode register burst table:
585 ** A2 A1 A0 lenght
586 ** 0 0 0 1
587 ** 0 0 1 2
588 ** 0 1 0 4
589 ** 0 1 1 8
590 ** 1 0 0 invalid
591 ** 1 0 1 invalid
592 ** 1 1 0 invalid
593 ** 1 1 1 page (only valid for non-interleaved)
594 */
595
596 burst_len = burst_to_len (burst_support);
597 burst_len = 2; /* FIXME */
598
599 if (banks[0].used) {
600 pci_write_cfg_word (0, 0, DRAM_PCR0,
601 0x8000 | burst_len | (banks[0].cas_used << 4));
602 debug ("Mode bank 0: 0x%08x\n",
603 0x8000 | burst_len | (banks[0].cas_used << 4));
604 } else {
605 /* Seems to be needed to disable the bank */
606 pci_write_cfg_word (0, 0, DRAM_PCR0, 0x0000 | 0x032);
607 }
608
609 if (banks[1].used) {
610 pci_write_cfg_word (0, 0, DRAM_PCR0,
611 0x9000 | burst_len | (banks[1].cas_used << 4));
612 debug ("Mode bank 1: 0x%08x\n",
613 0x8000 | burst_len | (banks[1].cas_used << 4));
614 } else {
615 /* Seems to be needed to disable the bank */
616 pci_write_cfg_word (0, 0, DRAM_PCR0, 0x1000 | 0x032);
617 }
618
619
620 if (banks[2].used) {
621 pci_write_cfg_word (0, 0, DRAM_PCR0,
622 0xa000 | burst_len | (banks[2].cas_used << 4));
623 debug ("Mode bank 2: 0x%08x\n",
624 0x8000 | burst_len | (banks[2].cas_used << 4));
625 } else {
626 /* Seems to be needed to disable the bank */
627 pci_write_cfg_word (0, 0, DRAM_PCR0, 0x2000 | 0x032);
628 }
629
630
631 if (banks[3].used) {
632 pci_write_cfg_word (0, 0, DRAM_PCR0,
633 0xb000 | burst_len | (banks[3].cas_used << 4));
634 debug ("Mode bank 3: 0x%08x\n",
635 0x8000 | burst_len | (banks[3].cas_used << 4));
636 } else {
637 /* Seems to be needed to disable the bank */
638 pci_write_cfg_word (0, 0, DRAM_PCR0, 0x3000 | 0x032);
639 }
640
641
642 pci_write_cfg_word (0, 0, 0xba, 0x00);
643
644 return total_ram;
645}
646
647extern int drv_isa_kbd_init (void);
648
649int last_stage_init (void)
650{
651 drv_isa_kbd_init ();
652 return 0;
653}
654
655int overwrite_console (void)
656{
657 return (0);
658}
659
660#define in_8 read_byte
661#define out_8 write_byte
662
663static __inline__ unsigned long get_msr (void)
664{
665 unsigned long msr;
666
667 asm volatile ("mfmsr %0":"=r" (msr):);
668
669 return msr;
670}
671
672static __inline__ void set_msr (unsigned long msr)
673{
674 asm volatile ("mtmsr %0"::"r" (msr));
675}
676
677int board_pre_init (void)
678{
679 unsigned char c_value = 0;
680 unsigned long msr;
681
682 /* Basic init of PS/2 keyboard (needed for some reason)... */
683 /* Ripped from John's code */
684 while ((in_8 ((unsigned char *) 0xfe000064) & 0x02) != 0);
685 out_8 ((unsigned char *) 0xfe000064, 0xaa);
686 while ((in_8 ((unsigned char *) 0xfe000064) & 0x01) == 0);
687 c_value = in_8 ((unsigned char *) 0xfe000060);
688 while ((in_8 ((unsigned char *) 0xfe000064) & 0x02) != 0);
689 out_8 ((unsigned char *) 0xfe000064, 0xab);
690 while ((in_8 ((unsigned char *) 0xfe000064) & 0x01) == 0);
691 c_value = in_8 ((unsigned char *) 0xfe000060);
692 while ((in_8 ((unsigned char *) 0xfe000064) & 0x02) != 0);
693 out_8 ((unsigned char *) 0xfe000064, 0xae);
694/* while ((in_8((unsigned char *)0xfe000064) & 0x01) == 0); */
695/* c_value = in_8((unsigned char *)0xfe000060); */
696
697 /* Enable FPU */
698 msr = get_msr ();
699 set_msr (msr | MSR_FP);
700
701 via_calibrate_bus_freq ();
702
703 return 0;
704}