2 * This file is part of the coreboot project.
4 * Copyright (C) 2009-2010 iWave Systems
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <arch/romcc_io.h>
24 #include <device/pci_def.h>
25 #include <device/pnp_def.h>
26 #include <cpu/x86/lapic.h>
27 #include <cpu/x86/cache.h>
29 #include <console/console.h>
31 #include "ram/ramtest.c"
32 #include "southbridge/intel/sch/early_smbus.c"
38 #define RFID_ADDR 0xA0
39 #define RFID_SELECT_CARD_COMMAND 0x01
40 #define SELECT_COMMAND_LENGTH 0x01
42 #define SMBUS_BASE_ADDRESS 0x400
44 static u32 sch_SMbase_read(void)
49 SMBusBase = pci_read_config32(PCI_DEV(0, 0x1f, 0), 0x40);
51 printk(BIOS_DEBUG, "SMBus base = %x\r\n", SMBusBase);
55 static void sch_SMbase_init(void)
59 SMBusBase = sch_SMbase_read();
60 outb(0x3F, SMBusBase + SMBCLKDIV);
63 static void sch_SMbus_regs(void)
67 SMBusBase = sch_SMbase_read();
68 printk(BIOS_DEBUG, "SMBHSTCNT. =%x\r\n", inb(SMBusBase + SMBHSTCNT));
69 printk(BIOS_DEBUG, "SMBHSTSTS. =%x\r\n", inb(SMBusBase + SMBHSTSTS));
70 printk(BIOS_DEBUG, "SMBCLKDIV. =%x\r\n", inb(SMBusBase + SMBCLKDIV));
72 printk(BIOS_DEBUG, "SMBHSTADD. =%x\r\n", inb(SMBusBase + SMBHSTADD));
73 printk(BIOS_DEBUG, "SMBHSTCMD. =%x\r\n", inb(SMBusBase + SMBHSTCMD));
80 SMBusBase = sch_SMbase_read();
81 outb(0x00, SMBusBase + SMBHSTCNT);
82 outb(0x07, SMBusBase + SMBHSTSTS);
89 SMBusBase = sch_SMbase_read();
90 outb(0x00, SMBusBase + SMBHSTDAT0);
91 outb(0x00, SMBusBase + SMBHSTCMD);
92 outb(0x00, SMBusBase + SMBHSTDAT1);
93 outb(0x00, SMBusBase + SMBHSTDATB);
94 outb(0x00, SMBusBase + (SMBHSTDATB + 0x1));
95 outb(0x00, SMBusBase + (SMBHSTDATB + 0x2));
96 outb(0x00, SMBusBase + (SMBHSTDATB + 0x3));
97 outb(0x00, SMBusBase + (SMBHSTDATB + 0x4));
98 outb(0x00, SMBusBase + (SMBHSTDATB + 0x5));
99 outb(0x00, SMBusBase + (SMBHSTDATB + 0x6));
102 void transaction1(unsigned char dev_addr)
107 SMBusBase = sch_SMbase_read();
108 printk(BIOS_DEBUG, "Transaction 1");
109 //clear the control and status registers
111 //clear the data register
113 //program TSA register
114 outb(dev_addr, SMBusBase + SMBHSTADD);
115 //program command register
116 outb(0x04, SMBusBase + SMBHSTCMD);
117 //write data register
118 outb(0x04, SMBusBase + SMBHSTDAT0);
119 outb(0x04, SMBusBase + SMBHSTDATB);
121 outb(0x09, SMBusBase + (SMBHSTDATB + 0x1));
122 outb(0x11, SMBusBase + (SMBHSTDATB + 0x2));
123 outb(0x22, SMBusBase + (SMBHSTDATB + 0x3));
125 //set the control register
126 outb(0x15, SMBusBase + SMBHSTCNT);
127 //check the status register for busy state
129 temp = inb(SMBusBase + SMBHSTSTS);
130 //printk(BIOS_DEBUG, "SMBus Busy.. status =%x\r\n",temp);
131 //printk(BIOS_DEBUG, "SMBHSTSTS. =%x\r\n",inb(SMBusBase+SMBHSTSTS));
133 temp = inb(SMBusBase + SMBHSTSTS);
134 printk(BIOS_DEBUG, "SMBus Busy.. status =%x\r\n", temp);
136 printk(BIOS_DEBUG, "SMBHSTSTS. =%x\r\n",
137 inb(SMBusBase + SMBHSTSTS));
144 printk(BIOS_DEBUG, "SMBus Success");
147 printk(BIOS_DEBUG, "SMBus error %d", temp);
152 printk(BIOS_DEBUG, "Command in TRansaction 1=%x\r\n\n",
153 inb(SMBusBase + SMBHSTCMD));
156 void transaction2(unsigned char dev_addr)
161 SMBusBase = sch_SMbase_read();
162 printk(BIOS_DEBUG, "Transaction 2");
163 //clear the control and status registers
165 //clear the data register
167 //program TSA register
168 outb(dev_addr, SMBusBase + SMBHSTADD);
169 //program command register
170 outb(0x03, SMBusBase + SMBHSTCMD);
171 //write data register
172 outb(0x02, SMBusBase + SMBHSTDAT0);
173 outb(0x03, SMBusBase + SMBHSTDATB);
174 outb(0x09, SMBusBase + (SMBHSTDATB + 0x1));
175 outb(0x15, SMBusBase + SMBHSTCNT);
176 //check the status register for busy state
178 temp = inb(SMBusBase + SMBHSTSTS);
179 //printk(BIOS_DEBUG, "SMBus Busy.. status =%x\r\n",temp);
180 //printk(BIOS_DEBUG, "SMBHSTSTS. =%x\r\n",inb(SMBusBase+SMBHSTSTS));
182 temp = inb(SMBusBase + SMBHSTSTS);
183 printk(BIOS_DEBUG, "SMBus Busy.. status =%x\r\n", temp);
185 printk(BIOS_DEBUG, "SMBHSTSTS. =%x\r\n",
186 inb(SMBusBase + SMBHSTSTS));
193 printk(BIOS_DEBUG, "SMBus Success");
196 printk(BIOS_DEBUG, "SMBus error %d", temp);
202 printk(BIOS_DEBUG, "Command in TRansaction 2=%x\r\n\n",
203 inb(SMBusBase + SMBHSTCMD));
206 void transaction3(unsigned char dev_addr)
208 int temp, index, length;
211 SMBusBase = sch_SMbase_read();
212 printk(BIOS_DEBUG, "smb_read_multiple_bytes");
215 outb(dev_addr, SMBusBase + SMBHSTADD);
216 outb(0x03, SMBusBase + SMBHSTCMD);
217 outb(0x11, SMBusBase + SMBHSTCNT);
220 outb(dev_addr + 1, SMBusBase + SMBHSTADD);
222 outb(0x15, SMBusBase + SMBHSTCNT);
224 // sch_SMbus_regs ();
225 //check the status register for busy state
226 //temp=inb(SMBusBase+SMBHSTSTS);
227 //printk(BIOS_DEBUG, "SMBus Busy.. status =%x\r\n",temp);
229 //printk(BIOS_DEBUG, "SMBHSTSTS. =%x\r\n",inb(SMBusBase+SMBHSTSTS));
231 temp = inb(SMBusBase + SMBHSTSTS);
232 printk(BIOS_DEBUG, "SMBHSTSTS. =%x\r\n",
233 inb(SMBusBase + SMBHSTSTS));
241 printk(BIOS_DEBUG, "SMBus Success\n");
244 printk(BIOS_DEBUG, "SMBus error %d", temp);
250 printk(BIOS_DEBUG, "ADDRESS is.. %x\r\n", inb(SMBusBase + SMBHSTADD));
251 length = inb(SMBusBase + SMBHSTDAT0);
253 printk(BIOS_DEBUG, "Length is.. %x\r\n", inb(SMBusBase + SMBHSTDAT0));
255 printk(BIOS_DEBUG, "Command is... %x\r\n", inb(SMBusBase + SMBHSTDATB));
256 printk(BIOS_DEBUG, "Status .. %x\r\n", inb(SMBusBase + SMBHSTDATB + 1));
257 for (index = 0; index < length; index++)
258 printk(BIOS_DEBUG, "Serial Byte[%x]..%x\r\n", index,
259 inb(SMBusBase + SMBHSTDATB + index));
266 printk(BIOS_DEBUG, "%s", "\r\nCase 9....... \n\r");
267 // send the length byte and command code through RFID interface
269 transaction1(RFID_ADDR);
270 transaction2(RFID_ADDR);
271 transaction3(RFID_ADDR);
276 #include "northbridge/intel/sch/early_init.c"
277 #include "northbridge/intel/sch/raminit.h"
278 #include "northbridge/intel/sch/raminit.c"
280 static void sch_enable_lpc(void)
282 /* Initialize the FWH decode/Enable registers according to platform design */
283 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xD0, 0x00112233);
284 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0xD4, 0xC0000000);
285 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0x60, 0x808A8B8B);
286 pci_write_config32(PCI_DEV(0, 0x1f, 0), 0x64, 0x8F898F89);
289 static void sch_shadow_CMC(void)
293 /* FIXME: proper dest, proper src, and wbinvd, too */
294 memcpy((void *)CMC_SHADOW, (void *)0xfffd0000, 64 * 1024);
295 // __asm__ volatile ("wbinvd \n"
297 printk(BIOS_DEBUG, "copy done ");
298 memcpy((void *)0x3f5f0000, (void *)0x3faf0000, 64 * 1024);
299 printk(BIOS_DEBUG, "copy 2 done ");
300 reg32 = cpuid_eax(0x00000001);
301 printk(BIOS_INFO, "CPU ID: %d.\n", reg32);
303 reg32 = cpuid_eax(0x80000008);
304 printk(BIOS_INFO, "Physical Address size: %d.\n", (reg32 & 0xFF));
305 printk(BIOS_INFO, "Virtual Address size: %d.\n",
306 ((reg32 & 0xFF00) >> 8));
307 sch_port_access_write_ram_cmd(0xB8, 4, 0, 0x3faf0000);
308 printk(BIOS_DEBUG, "1 ");
309 sch_port_access_write_ram_cmd(0xBA, 4, 0, reg32);
310 printk(BIOS_DEBUG, "2 ");
313 static void poulsbo_setup_Stage1Regs(void)
317 printk(BIOS_DEBUG, "E000/F000 Routing ");
318 reg32 = sch_port_access_read(2, 3, 4);
319 sch_port_access_write(2, 3, 4, (reg32 | 0x6));
322 static void poulsbo_setup_Stage2Regs(void)
326 printk(BIOS_DEBUG, "Reserved");
327 reg32 = pci_read_config32(PCI_DEV(0, 0x2, 0), 0x62);
328 pci_write_config32(PCI_DEV(0, 0x2, 0), 0x62, (reg32 | 0x3));
329 /* Slot capabilities */
330 pci_write_config32(PCI_DEV(0, 28, 0), 0x54, 0x80500);
331 pci_write_config32(PCI_DEV(0, 28, 1), 0x54, 0x100500);
332 /* FIXME: CPU ID identification */
333 printk(BIOS_DEBUG, " done.\n");
336 void main(unsigned long bist)
347 /* Halt if there was a built in self test failure */
348 // report_bist_failure(bist);
349 // outl (0x00, 0x1088);
352 * Perform some early chipset initialization required
353 * before RAM initialization can work.
355 sch_early_initialization();
356 sdram_initialize(boot_mode);
359 poulsbo_setup_Stage1Regs();
360 poulsbo_setup_Stage2Regs();
364 /* Perform some initialization that must run before stage2. */
368 * This should probably go away. Until now it is required
369 * and mainboard specific.
372 /* Chipset Errata! */
373 pci_write_config16(PCI_DEV(0, 0x2, 0), GGC, 0x20);
374 pci_write_config32(PCI_DEV(0, 0x2, 0), 0xc4, 0x00000002);
375 pci_write_config32(PCI_DEV(0, 0x2, 0), 0xe0, 0x00008000);
376 pci_write_config32(PCI_DEV(0, 0x2, 0), 0xf0, 0x00000005);
377 pci_write_config16(PCI_DEV(0, 0x2, 0), 0xf7, 0x80);
378 pci_write_config16(PCI_DEV(0, 0x2, 0), 0x4, 0x7);