1 #define HAVE_STRING_SUPPORT 0
2 #define HAVE_CAST_SUPPORT 0
3 #define HAVE_STATIC_ARRAY_SUPPORT 0
4 #define HAVE_POINTER_SUPPORT 0
6 void outb(unsigned char value, unsigned short port)
8 __builtin_outb(value, port);
11 void outw(unsigned short value, unsigned short port)
13 __builtin_outw(value, port);
16 void outl(unsigned int value, unsigned short port)
18 __builtin_outl(value, port);
21 unsigned char inb(unsigned short port)
23 return __builtin_inb(port);
26 unsigned char inw(unsigned short port)
28 return __builtin_inw(port);
31 unsigned char inl(unsigned short port)
33 return __builtin_inl(port);
36 static unsigned int config_cmd(unsigned char bus, unsigned devfn, unsigned where)
38 return 0x80000000 | (bus << 16) | (devfn << 8) | (where & ~3);
41 static unsigned char pcibios_read_config_byte(
42 unsigned char bus, unsigned devfn, unsigned where)
44 outl(config_cmd(bus, devfn, where), 0xCF8);
45 return inb(0xCFC + (where & 3));
48 static unsigned short pcibios_read_config_word(
49 unsigned char bus, unsigned devfn, unsigned where)
51 outl(config_cmd(bus, devfn, where), 0xCF8);
52 return inw(0xCFC + (where & 2));
55 static unsigned int pcibios_read_config_dword(
56 unsigned char bus, unsigned devfn, unsigned where)
58 outl(config_cmd(bus, devfn, where), 0xCF8);
63 static void pcibios_write_config_byte(
64 unsigned char bus, unsigned devfn, unsigned where, unsigned char value)
66 outl(config_cmd(bus, devfn, where), 0xCF8);
67 outb(value, 0xCFC + (where & 3));
70 static void pcibios_write_config_word(
71 unsigned char bus, unsigned devfn, unsigned where, unsigned short value)
73 outl(config_cmd(bus, devfn, where), 0xCF8);
74 outw(value, 0xCFC + (where & 2));
77 static void pcibios_write_config_dword(
78 unsigned char bus, unsigned devfn, unsigned where, unsigned int value)
80 outl(config_cmd(bus, devfn, where), 0xCF8);
86 #define TTYS0_BASE 0x3f8
90 #define TTYS0_BAUD 115200
93 #if ((115200%TTYS0_BAUD) != 0)
94 #error Bad ttys0 baud rate
97 #define TTYS0_DIV (115200/TTYS0_BAUD)
99 /* Line Control Settings */
101 /* Set 8bit, 1 stop bit, no parity */
102 #define TTYS0_LCS 0x3
105 #define UART_LCS TTYS0_LCS
108 #define UART_RBR 0x00
109 #define UART_TBR 0x00
112 #define UART_IER 0x01
113 #define UART_IIR 0x02
114 #define UART_FCR 0x02
115 #define UART_LCR 0x03
116 #define UART_MCR 0x04
117 #define UART_DLL 0x00
118 #define UART_DLM 0x01
121 #define UART_LSR 0x05
122 #define UART_MSR 0x06
123 #define UART_SCR 0x07
125 int uart_can_tx_byte(void)
127 return inb(TTYS0_BASE + UART_LSR) & 0x20;
130 void uart_wait_to_tx_byte(void)
132 while(!uart_can_tx_byte())
136 void uart_wait_until_sent(void)
138 while(!(inb(TTYS0_BASE + UART_LSR) & 0x40))
142 void uart_tx_byte(unsigned char data)
144 uart_wait_to_tx_byte();
145 outb(data, TTYS0_BASE + UART_TBR);
146 /* Make certain the data clears the fifos */
147 uart_wait_until_sent();
152 /* disable interrupts */
153 outb(0x0, TTYS0_BASE + UART_IER);
155 outb(0x01, TTYS0_BASE + UART_FCR);
156 /* Set Baud Rate Divisor to 12 ==> 115200 Baud */
157 outb(0x80 | UART_LCS, TTYS0_BASE + UART_LCR);
158 outb(TTYS0_DIV & 0xFF, TTYS0_BASE + UART_DLL);
159 outb((TTYS0_DIV >> 8) & 0xFF, TTYS0_BASE + UART_DLM);
160 outb(UART_LCS, TTYS0_BASE + UART_LCR);
163 void __console_tx_char(unsigned char byte)
167 void __console_tx_nibble(unsigned nibble)
170 digit = nibble + '0';
174 __console_tx_char(digit);
176 void __console_tx_hex8(unsigned char byte)
178 __console_tx_nibble(byte >> 4);
179 __console_tx_nibble(byte & 0x0f);
182 void __console_tx_hex32(unsigned char value)
184 __console_tx_nibble((value >> 28) & 0x0f);
185 __console_tx_nibble((value >> 24) & 0x0f);
186 __console_tx_nibble((value >> 20) & 0x0f);
187 __console_tx_nibble((value >> 16) & 0x0f);
188 __console_tx_nibble((value >> 12) & 0x0f);
189 __console_tx_nibble((value >> 8) & 0x0f);
190 __console_tx_nibble((value >> 4) & 0x0f);
191 __console_tx_nibble(value & 0x0f);
194 #if HAVE_STRING_SUPPORT
195 void __console_tx_string(char *str)
198 while((ch = *str++) != '\0') {
199 __console_tx_byte(ch);
203 void __console_tx_string(char *str)
209 void print_emerg_char(unsigned char byte) { __console_tx_char(byte); }
210 void print_emerg_hex8(unsigned char value) { __console_tx_hex8(value); }
211 void print_emerg_hex32(unsigned int value) { __console_tx_hex32(value); }
212 void print_emerg(char *str) { __console_tx_string(str); }
214 void print_alert_char(unsigned char byte) { __console_tx_char(byte); }
215 void print_alert_hex8(unsigned char value) { __console_tx_hex8(value); }
216 void print_alert_hex32(unsigned int value) { __console_tx_hex32(value); }
217 void print_alert(char *str) { __console_tx_string(str); }
219 void print_crit_char(unsigned char byte) { __console_tx_char(byte); }
220 void print_crit_hex8(unsigned char value) { __console_tx_hex8(value); }
221 void print_crit_hex32(unsigned int value) { __console_tx_hex32(value); }
222 void print_crit(char *str) { __console_tx_string(str); }
224 void print_err_char(unsigned char byte) { __console_tx_char(byte); }
225 void print_err_hex8(unsigned char value) { __console_tx_hex8(value); }
226 void print_err_hex32(unsigned int value) { __console_tx_hex32(value); }
227 void print_err(char *str) { __console_tx_string(str); }
229 void print_warning_char(unsigned char byte) { __console_tx_char(byte); }
230 void print_warning_hex8(unsigned char value) { __console_tx_hex8(value); }
231 void print_warning_hex32(unsigned int value) { __console_tx_hex32(value); }
232 void print_warning(char *str) { __console_tx_string(str); }
234 void print_notice_char(unsigned char byte) { __console_tx_char(byte); }
235 void print_notice_hex8(unsigned char value) { __console_tx_hex8(value); }
236 void print_notice_hex32(unsigned int value) { __console_tx_hex32(value); }
237 void print_notice(char *str) { __console_tx_string(str); }
239 void print_info_char(unsigned char byte) { __console_tx_char(byte); }
240 void print_info_hex8(unsigned char value) { __console_tx_hex8(value); }
241 void print_info_hex32(unsigned int value) { __console_tx_hex32(value); }
242 void print_info(char *str) { __console_tx_string(str); }
244 void print_debug_char(unsigned char byte) { __console_tx_char(byte); }
245 void print_debug_hex8(unsigned char value) { __console_tx_hex8(value); }
246 void print_debug_hex32(unsigned int value) { __console_tx_hex32(value); }
247 void print_debug(char *str) { __console_tx_string(str); }
249 void print_spew_char(unsigned char byte) { __console_tx_char(byte); }
250 void print_spew_hex8(unsigned char value) { __console_tx_hex8(value); }
251 void print_spew_hex32(unsigned int value) { __console_tx_hex32(value); }
252 void print_spew(char *str) { __console_tx_string(str); }
254 #define PIIX4_DEVFN 0x90
255 #define SMBUS_MEM_DEVICE_START 0x50
256 #define SMBUS_MEM_DEVICE_END 0x53
257 #define SMBUS_MEM_DEVICE_INC 1
261 #define PM_DEVFN (PIIX4_DEVFN+3)
263 #define SMBUS_IO_BASE 0x1000
272 void smbus_enable(void)
275 pcibios_write_config_dword(PM_BUS, PM_DEVFN, 0x90, SMBUS_IO_BASE | 1);
277 pcibios_write_config_byte(PM_BUS, PM_DEVFN, 0xd2, (0x4 << 1) | 1);
279 pcibios_write_config_word(PM_BUS, PM_DEVFN, 0x4, 1);
282 void smbus_setup(void)
284 outb(0, SMBUS_IO_BASE + SMBHSTSTAT);
287 static void smbus_wait_until_ready(void)
289 while((inb(SMBUS_IO_BASE + SMBHSTSTAT) & 1) == 1) {
294 static void smbus_wait_until_done(void)
298 byte = inb(SMBUS_IO_BASE + SMBHSTSTAT);
299 }while((byte &1) == 1);
300 while( (byte & ~1) == 0) {
301 byte = inb(SMBUS_IO_BASE + SMBHSTSTAT);
305 int smbus_read_byte(unsigned device, unsigned address)
307 unsigned char host_status_register;
311 smbus_wait_until_ready();
313 /* setup transaction */
314 /* disable interrupts */
315 outb(inb(SMBUS_IO_BASE + SMBHSTCTL) & (~1), SMBUS_IO_BASE + SMBHSTCTL);
316 /* set the device I'm talking too */
317 outb(((device & 0x7f) << 1) | 1, SMBUS_IO_BASE + SMBHSTADD);
318 /* set the command/address... */
319 outb(address & 0xFF, SMBUS_IO_BASE + SMBHSTCMD);
320 /* set up for a byte data read */
321 outb((inb(SMBUS_IO_BASE + SMBHSTCTL) & 0xE3) | (0x2 << 2), SMBUS_IO_BASE + SMBHSTCTL);
323 /* clear any lingering errors, so the transaction will run */
324 outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT);
326 /* clear the data byte...*/
327 outb(0, SMBUS_IO_BASE + SMBHSTDAT0);
329 /* start the command */
330 outb((inb(SMBUS_IO_BASE + SMBHSTCTL) | 0x40), SMBUS_IO_BASE + SMBHSTCTL);
332 /* poll for transaction completion */
333 smbus_wait_until_done();
335 host_status_register = inb(SMBUS_IO_BASE + SMBHSTSTAT);
337 /* read results of transaction */
338 byte = inb(SMBUS_IO_BASE + SMBHSTDAT0);
341 if (host_status_register != 0x02) {
348 #define I440GX_DEVFN ((0x00 << 3) + 0)
352 #define CAS_LATENCY 3
355 #if (CAS_LATENCY == 2)
361 #define CAS_MODE 0x2a
369 #if (CAS_LATENCY == 3)
375 #define CAS_MODE 0x3a
383 #error "Nothing defined"
386 /* Default values for config registers */
388 static void set_nbxcfg(void)
390 /* NBXCFG 0x50 - 0x53 */
399 * SDRAM Row without ECC:
408 * Host Bus Fast Data Ready Enable == 0 Disabled
409 * IDSEL_REDIRECT == 0 (430TX compatibility disable?)
410 * WSC# Hanshake Disable == 0 enable (Use External IOAPIC)
411 * Host/DRAM Frequence == 00 100Mhz
412 * AGP to PCI Access Enable == 0 Disable
413 * PCI Agent to Aperture Access Disable == 0 Enable (Ignored)
414 * Aperture Access Global Enable == 0 Disable
415 * DRAM Data Integrity Mode == 11 (Error Checking/Correction)
416 * ECC Diagnostic Mode Enable == 0 Not Enabled
417 * MDA present == 0 Not Present
418 * USWC Write Post During During I/O Bridge Access Enable == 1 Enabled
419 * In Order Queue Depth (IQD) (RO) == ??
421 pcibios_write_config_dword(I440GX_BUS, I440GX_DEVFN, 0x50, 0xff00000c);
424 static void set_dramc(void)
428 * Not registered SDRAM
431 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x57, 0x8);
434 static void set_pam(void)
436 /* PAM - Programmable Attribute Map Registers */
437 /* Ideally we want to enable all of these as DRAM and teach
438 * linux it is o.k. to use them...
440 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x59, 0x00);
441 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x5a, 0x00);
442 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x5b, 0x00);
443 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x5d, 0x00);
444 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x5e, 0x00);
445 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x5f, 0x00);
448 static void set_drb(void)
450 /* DRB - DRAM Row Boundary Registers */
451 /* Conservative setting 8MB of ram on first DIMM... */
452 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x60, 0x01);
453 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x61, 0x01);
454 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x62, 0x01);
455 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x63, 0x01);
456 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x64, 0x01);
457 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x65, 0x01);
458 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x66, 0x01);
459 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x67, 0x01);
462 static void set_fdhc(void)
464 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x68, 0x00);
466 static void set_mbsc(void)
468 /* MBSC - Memory Buffer Strength Control */
482 * MAA[14:0]#, WEA#, SRASA#, SCASA# Buffer Strengths == 3x
483 * MAB[14,13,10,12:11,9:0]#, WEB#, SRASB#, SCASB# Buffer Strengths == 3x
484 * MD[63:0]# Buffer Strength Control 2 == 3x
485 * MD[63:0]# Buffer Strength Control 1 == 3x
486 * MECC[7:0] Buffer Strength Control 2 == 3x
487 * MECC[7:0] Buffer Strength Control 1 == 3x
488 * CSB7# Buffer Strength == 3x
489 * CSA7# Buffer Strength == 3x
490 * CSB6# Buffer Strength == 3x
491 * CSA6# Buffer Strength == 3x
492 * CSA5#/CSB5# Buffer Strength == 2x
493 * CSA4#/CSB4# Buffer Strength == 2x
494 * CSA3#/CSB3# Buffer Strength == 2x
495 * CSA2#/CSB2# Buffer Strength == 2x
496 * CSA1#/CSB1# Buffer Strength == 2x
497 * CSA0#/CSB0# Buffer Strength == 2x
498 * DQMA5 Buffer Strength == 2x
499 * DQMA1 Buffer Strength == 3x
500 * DQMB5 Buffer Strength == 2x
501 * DQMB1 Buffer Strength == 2x
502 * DQMA[7:6,4:2,0] Buffer Strength == 3x
503 * GCKE Buffer Strength == 1x
504 * FENA Buffer Strength == 3x
506 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x69, 0xB3);
507 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x6a, 0xee);
508 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x6b, 0xff);
509 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x6c, 0xff);
510 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x6d, 0xff);
511 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x6e, 0x03);
514 static void set_smram(void)
519 * SMM Compatible base segment == 010 (Hardcoded value)
523 static void set_esramc(void)
528 static void set_rps(void)
530 /* RPS - Row Page Size Register */
545 pcibios_write_config_word(I440GX_BUS, I440GX_DEVFN, 0x74, 0x5555);
548 static void set_sdramc(void)
550 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x76, CAS_NB);
553 static void set_pgpol(void)
555 /* PGPOL - Paging Policy Register */
569 * Dram Idle Timer (DIT) == 32 clocks
571 pcibios_write_config_word(I440GX_BUS, I440GX_DEVFN, 0x78, 0xff07);
574 static void set_mbfs(void)
576 /* MBFS - Memory Buffer Frequencey Select Register */
584 * MAA[14:0], WEA#, SRASA#, SCASA# == 100Mhz Buffers Enabled
585 * MAB[14,13,10,12:11,9:0], WEB#, SRASB#, SCASB# == 100Mhz Buffers Enabled
586 * MD[63:0] Control 2 == 100 Mhz Buffer Enable
587 * MD[63:0] Control 1 == 100 Mhz B
588 * MECC[7:0] Control 2 == 100 Mhz B
591 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xca, 0xff);
592 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xcb, 0xff);
593 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xcc, 0x7f);
596 static void set_dwtc(void)
598 /* DWTC - DRAM Write Thermal Throttle Control */
599 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xe0, 0xb4);
600 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xe1, 0xbe);
601 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xe2, 0xff);
602 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xe3, 0xd7);
603 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xe4, 0x97);
604 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xe5, 0x3e);
605 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xe6, 0x00);
606 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xe7, 0x80);
609 static void set_drtc(void)
611 /* DRTC - DRAM Read Thermal Throttle Control */
612 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xe8, 0x2c);
613 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xe9, 0xd3);
614 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xea, 0xf7);
615 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xeb, 0xcf);
616 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xec, 0x9d);
617 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xed, 0x3e);
618 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xee, 0x00);
619 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xef, 0x00);
622 static void set_pmcr(void)
624 /* PMCR -- BIOS sets 0x90 into it.
626 * we have never used it. So why did this ever work?
628 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x7a, 0x90);
631 void sdram_set_registers(void)
652 /* __builtin_bsr is a exactly equivalent to the x86 machine
653 * instruction with the exception that it returns -1
654 * when the value presented to it is zero.
655 * Otherwise __builtin_bsr returns the zero based index of
656 * the highest bit set.
658 return __builtin_bsr(value);
662 static void spd_set_drb(void)
665 * Effects: Uses serial presence detect to set the
666 * DRB registers which holds the ending memory address assigned
669 unsigned end_of_memory;
673 end_of_memory = 0; /* in multiples of 8MiB */
674 device = SMBUS_MEM_DEVICE_START;
676 while (device <= SMBUS_MEM_DEVICE_END) {
677 unsigned side1_bits, side2_bits;
680 side1_bits = side2_bits = -1;
683 byte = smbus_read_byte(device, 3);
685 side1_bits += byte & 0xf;
688 byte = smbus_read_byte(device, 4);
689 side1_bits += byte & 0xf;
692 byte = smbus_read_byte(device, 17);
693 side1_bits += log2(byte);
695 /* Get the moduel data width and convert it to a power of two */
697 byte = smbus_read_byte(device, 6);
700 byte2 = smbus_read_byte(device, 7);
701 #if HAVE_CAST_SUPPORT
702 side1_bits += log2((((unsigned long)byte2 << 8)| byte));
704 side1_bits += log2((byte2 << 8) | byte);
707 /* now I have the ram size in bits as a power of two (less 1) */
708 /* Make it mulitples of 8MB */
713 /* number of physical banks */
714 byte = smbus_read_byte(device, 5);
716 /* for now only handle the symmetrical case */
717 side2_bits = side1_bits;
721 /* Compute the end address for the DRB register */
722 /* Only process dimms < 2GB (2^8 * 8MB) */
723 if (side1_bits < 8) {
724 end_of_memory += (1 << side1_bits);
726 #if HAVE_STRING_SUPPORT
727 print_debug("end_of_memory: "); print_debug_hex32(end_of_memory); print_debug("\n");
729 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, drb_reg, end_of_memory);
731 if (side2_bits < 8 ) {
732 end_of_memory += (1 << side2_bits);
734 #if HAVE_STRING_SUPPORT
735 print_debug("end_of_memory: "); print_debug_hex32(end_of_memory); print_debug("\n");
737 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, drb_reg +1, end_of_memory);
740 device += SMBUS_MEM_DEVICE_INC;
744 void sdram_no_memory(void)
746 #if HAVE_STRING_SUPPORT
747 print_err("No memory!!\n");
752 static void spd_set_dramc(void)
755 * Effects: Uses serial presence detect to set the
756 * DRAMC register, which records if ram is registerd or not,
757 * and controls the refresh rate.
758 * The refresh rate is not set here, as memory refresh
759 * cannot be enbaled until after memory is initialized.
760 * see spd_enable_refresh.
762 /* auto detect if ram is registered or not. */
763 /* The DRAMC register also contorls the refresh rate but we can't
764 * set that here because we must leave refresh disabled.
765 * see: spd_enable_refresh
767 /* Find the first dimm and assume the rest are the same */
768 /* FIXME Check for illegal/unsupported ram configurations and abort */
773 device = SMBUS_MEM_DEVICE_START;
775 while ((byte < 0) && (device <= SMBUS_MEM_DEVICE_END)) {
776 byte = smbus_read_byte(device, 21);
777 device += SMBUS_MEM_DEVICE_INC;
780 /* We couldn't find anything we must have no memory */
784 if ((byte & 0x12) != 0) {
785 /* this is a registered part.
786 * observation: for register parts, BIOS zeros (!)
787 * registers CA-CC. This has an undocumented meaning.
789 /* But it does make sense the oppisite of registered
790 * sdram is buffered and 0xca - 0xcc control the buffers.
791 * Clearing them aparently disables them.
793 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xca, 0);
794 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xcb, 0);
795 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0xcc, 0);
798 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x57, dramc);
801 static void spd_enable_refresh(void)
804 * Effects: Uses serial presence detect to set the
805 * refresh rate in the DRAMC register.
806 * see spd_set_dramc for the other values.
807 * FIXME: Check for illegal/unsupported ram configurations and abort
809 #if HAVE_STATIC_ARRAY_SUPPORT
810 static const unsigned char refresh_rates[] = {
811 0x01, /* Normal 15.625 us -> 15.6 us */
812 0x05, /* Reduced(.25X) 3.9 us -> 7.8 us */
813 0x05, /* Reduced(.5X) 7.8 us -> 7.8 us */
814 0x02, /* Extended(2x) 31.3 us -> 31.2 us */
815 0x03, /* Extended(4x) 62.5 us -> 62.4 us */
816 0x04, /* Extended(8x) 125 us -> 124.8 us */
819 /* Find the first dimm and assume the rest are the same */
823 unsigned refresh_rate;
826 device = SMBUS_MEM_DEVICE_START;
827 while ((byte < 0) && (device <= SMBUS_MEM_DEVICE_END)) {
828 byte = smbus_read_byte(device, 12);
829 device += SMBUS_MEM_DEVICE_INC;
832 /* We couldn't find anything we must have no memory */
836 /* Default refresh rate be conservative */
838 /* see if the ram refresh is a supported one */
840 #if HAVE_STATIC_ARRAY_SUPPORT
841 refresh_rate = refresh_rates[byte];
844 byte = pcibios_read_config_byte(I440GX_BUS, I440GX_DEVFN, 0x57);
846 byte |= refresh_rate;
847 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x57, byte);
850 static void spd_set_sdramc(void)
855 static void spd_set_rps(void)
858 * Effects: Uses serial presence detect to set the row size
860 * FIXME: Check for illegal/unsupported ram configurations and abort
862 /* The RPS register holds the size of a ``page'' of DRAM on each DIMM */
867 /* default all page sizes to 2KB */
870 device = SMBUS_MEM_DEVICE_START;
871 for(; device <= SMBUS_MEM_DEVICE_END; index += 4, device += SMBUS_MEM_DEVICE_INC) {
876 byte = smbus_read_byte(device, 3);
877 if (byte < 0) continue;
879 /* I now have the row page size as a power of 2 */
880 page_size = byte & 0xf;
881 /* make it in multiples of 2Kb */
884 if (page_size <= 0) continue;
886 /* FIXME: do something with page sizes greather than 8KB!! */
887 page_sizes |= (page_size << index);
890 byte = smbus_read_byte(device, 5);
891 if (byte <= 1) continue;
893 /* For now only handle the symmetrical case */
894 page_sizes |= (page_size << (index +2));
896 /* next block is for Ron's attempt to get registered to work. */
897 /* we have just verified that we have to have this code. It appears that
898 * the registered SDRAMs do indeed set the RPS wrong. sheesh.
900 /* at this point, page_sizes holds the RPS for all ram.
901 * we have verified that for registered DRAM the values are
902 * 1/2 the size they should be. So we test for registered
903 * and then double the sizes if needed.
906 dramc = pcibios_read_config_byte(I440GX_BUS, I440GX_DEVFN, 0x57);
910 /* BIOS makes weird page size for registered! */
911 /* what we have found is you need to set the EVEN banks to
912 * twice the size. Fortunately there is a very easy way to
913 * do this. First, read the WORD value of register 0x74.
915 page_sizes += 0x1111;
918 pcibios_write_config_word(I440GX_BUS, I440GX_DEVFN, 0x74, page_sizes);
921 static void spd_set_pgpol(void)
924 * Effects: Uses serial presence detect to set the number of banks
926 * FIXME: Check for illegal/unsupported ram configurations and abort
928 /* The PGPOL register stores the number of logical banks per DIMM,
929 * and number of clocks the DRAM controller waits in the idle
936 /* default all bank counts 2 */
939 device = SMBUS_MEM_DEVICE_START;
940 for(; device <= SMBUS_MEM_DEVICE_END;
941 bank += 2, device += SMBUS_MEM_DEVICE_INC) {
945 byte = smbus_read_byte(device, 17);
946 if (byte < 0) continue;
947 if (byte < 4) continue;
948 bank_sizes |= (1 << bank);
951 /* Number of physical banks */
952 byte = smbus_read_byte(device, 5);
953 if (byte <= 1) continue;
954 /* for now only handle the symmetrical case */
955 bank_sizes |= (1 << (bank +1));
957 reg = bank_sizes << 8;
958 reg |= 0x7; /* 32 clocks idle time */
959 pcibios_write_config_word(I440GX_BUS, I440GX_DEVFN, 0x78, reg);
962 static void spd_set_nbxcfg(void)
965 * Effects: Uses serial presence detect to set the
966 * ECC support flags in the NBXCFG register
967 * FIXME: Check for illegal/unsupported ram configurations and abort
973 /* Say all dimms have no ECC support */
977 device = SMBUS_MEM_DEVICE_START;
978 for(; device <= SMBUS_MEM_DEVICE_END; index += 2, device += SMBUS_MEM_DEVICE_INC) {
981 byte = smbus_read_byte(device, 11);
982 if (byte < 0) continue;
984 byte = 0; /* Disable ECC */
986 /* 0 == None, 1 == Parity, 2 == ECC */
987 if (byte != 2) continue;
991 /* number of physical banks */
992 byte = smbus_read_byte(device, 5);
993 if (byte <= 1) continue;
994 /* There is only the symmetrical case */
995 reg ^= (1 << (index +1));
997 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x53, reg);
998 /* Now see if reg is 0xff. If it is we are done. If not,
999 * we need to set 0x18 into regster 0x50.l
1000 * we will do this in two steps, first or in 0x80 to 0x50.b,
1001 * then or in 0x1 to 0x51.b
1003 #if HAVE_STRING_SUPPORT
1004 print_debug("spd_set_nbxcfg reg="); print_debug_hex8(reg); print_debug("\n");
1008 byte = pcibios_read_config_byte(I440GX_BUS, I440GX_DEVFN, 0x50);
1010 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x50, byte);
1011 byte = pcibios_read_config_byte(I440GX_BUS, I440GX_DEVFN, 0x51);
1013 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x51, byte);
1015 * We should be setting bit 2 in register 76 and we're not
1016 * technically we should see if CL=2 for the ram,
1017 * but registered is so screwed up that it's kind of a lost
1020 byte = pcibios_read_config_byte(I440GX_BUS, I440GX_DEVFN, 0x76);
1022 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x76, byte);
1023 #if HAVE_STRING_SUPPORT
1024 print_debug("spd_set_nbxcfg 0x76.b="); print_debug_hex8(byte); print_debug("\n");
1029 void sdram_set_spd_registers(void)
1039 void sdram_first_normal_reference(void)
1044 void sdram_special_finishup(void)
1049 static void set_ram_command(unsigned command)
1053 byte = pcibios_read_config_byte(I440GX_BUS, I440GX_DEVFN, 0x76);
1055 byte |= (command << 5);
1056 pcibios_write_config_byte(I440GX_BUS, I440GX_DEVFN, 0x76, byte);
1057 #if HAVE_STRING_SUPPORT
1058 print_debug("set_ram_command 0x76.b="); print_debug_hex8(byte); print_debug("\n");
1062 #define RAM_COMMAND_NONE 0x0
1063 #define RAM_COMMAND_NOOP 0x1
1064 #define RAM_COMMAND_PRECHARGE 0x2
1065 #define RAM_COMMAND_MRS 0x3
1066 #define RAM_COMMAND_CBR 0x4
1068 void sdram_set_command_none(void)
1070 set_ram_command(RAM_COMMAND_NONE);
1072 void sdram_set_command_noop(void)
1074 set_ram_command(RAM_COMMAND_NOOP);
1076 void sdram_set_command_precharge(void)
1078 set_ram_command(RAM_COMMAND_PRECHARGE);
1081 static unsigned long dimm_base(int n)
1084 unsigned long result;
1089 byte = pcibios_read_config_byte(I440GX_BUS, I440GX_DEVFN, 0x60 + (n - 1));
1095 static void dimms_read(unsigned long offset)
1098 for(i = 0; i < 8; i++) {
1099 unsigned long dummy;
1101 unsigned long next_base;
1103 next_base = dimm_base(i +1);
1104 addr = dimm_base(i);
1105 if (addr == next_base) {
1109 #if HAVE_STRING_SUPPORT
1110 print_debug("Reading ");
1111 print_debug_hex32(addr);
1114 #if HAVE_POINTER_SUPPORT
1115 dummy = RAM(unsigned long, addr);
1117 #if HAVE_STRING_SUPPORT
1118 print_debug("Reading ");
1119 print_debug_hex32(addr ^ 0xddf8);
1122 #if HAVE_POINTER_SUPPORT
1123 dummy = RAM(unsigned long, addr ^ 0xdff8);
1125 #if HAVE_STRING_SUPPORT
1126 print_debug("Read ");
1127 print_debug_hex32(addr);
1128 print_debug_hex32(addr ^ 0xddf8);
1134 void sdram_set_command_cbr(void)
1136 set_ram_command(RAM_COMMAND_CBR);
1139 void sdram_assert_command(void)
1144 void sdram_set_mode_register(void)
1148 set_ram_command(RAM_COMMAND_MRS);
1149 byte = pcibios_read_config_byte(I440GX_BUS, I440GX_DEVFN, 0x76);
1150 cas_mode = byte & 0x4;
1155 dimms_read(cas_mode);
1158 void sdram_enable_refresh(void)
1160 spd_enable_refresh();
1164 unsigned long sdram_get_ecc_size_bytes(void)
1168 /* FIXME handle the no ram case. */
1169 /* Read the RAM SIZE */
1170 byte = pcibios_read_config_byte(I440GX_BUS, I440GX_DEVFN, 0x67);
1171 /* Convert it to bytes */
1180 /* Dummy udelay code acting as a place holder... */
1181 void udelay(int count)
1187 void sdram_enable(void)
1189 #if HAVE_STRING_SUPPORT
1190 print_debug("Ram Enable 1\n");
1194 sdram_set_command_noop();
1196 sdram_assert_command();
1199 sdram_set_command_precharge();
1200 sdram_assert_command();
1202 /* wait until the all banks idle state... */
1203 #if HAVE_STRING_SUPPORT
1204 print_debug("Ram Enable 2\n");
1207 /* Now we need 8 AUTO REFRESH / CBR cycles to be performed */
1209 sdram_set_command_cbr();
1210 sdram_assert_command();
1211 sdram_assert_command();
1212 sdram_assert_command();
1213 sdram_assert_command();
1214 sdram_assert_command();
1215 sdram_assert_command();
1216 sdram_assert_command();
1217 sdram_assert_command();
1219 #if HAVE_STRING_SUPPORT
1220 print_debug("Ram Enable 3\n");
1223 /* mode register set */
1224 sdram_set_mode_register();
1226 * MAx[2:0 ] 010 == burst mode of 4
1227 * MAx[3:3 ] 1 == interleave wrap type
1228 * MAx[4:4 ] == CAS# latency bit
1233 #if HAVE_STRING_SUPPORT
1234 print_debug("Ram Enable 4\n");
1237 /* normal operation */
1238 sdram_set_command_none();
1240 #if HAVE_STRING_SUPPORT
1241 print_debug("Ram Enable 5\n");
1246 void sdram_initialize(void)
1248 #if HAVE_STRING_SUPPORT
1249 print_debug("Ram1\n");
1251 /* Set the registers we can set once to reasonable values */
1252 sdram_set_registers();
1254 #if HAVE_STRING_SUPPORT
1255 print_debug("Ram2\n");
1257 /* Now setup those things we can auto detect */
1258 sdram_set_spd_registers();
1260 #if HAVE_STRING_SUPPORT
1261 print_debug("Ram3\n");
1263 /* Now that everything is setup enable the SDRAM.
1264 * Some chipsets do the work for use while on others
1265 * we need to it by hand.
1269 #if HAVE_STRING_SUPPORT
1270 print_debug("Ram4\n");
1272 sdram_first_normal_reference();
1274 #if HAVE_STRING_SUPPORT
1275 print_debug("Ram5\n");
1277 sdram_enable_refresh();
1278 sdram_special_finishup();
1280 #if HAVE_STRING_SUPPORT
1281 print_debug("Ram6\n");