2 * This file is part of the coreboot project.
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * 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
20 #ifndef _SB800_EARLY_SETUP_C_
21 #define _SB800_EARLY_SETUP_C_
29 #define SMBUS_IO_BASE 0x6000 /* Is it a temporary SMBus I/O base address? */
32 static void pmio_write(u8 reg, u8 value)
35 outb(value, PM_INDEX + 1);
38 static u8 pmio_read(u8 reg)
41 return inb(PM_INDEX + 1);
44 static void sb800_acpi_init(void) {
45 pmio_write(0x60, ACPI_PM_EVT_BLK & 0xFF);
46 pmio_write(0x61, ACPI_PM_EVT_BLK >> 8);
47 pmio_write(0x62, ACPI_PM1_CNT_BLK & 0xFF);
48 pmio_write(0x63, ACPI_PM1_CNT_BLK >> 8);
49 pmio_write(0x64, ACPI_PM_TMR_BLK & 0xFF);
50 pmio_write(0x65, ACPI_PM_TMR_BLK >> 8);
51 pmio_write(0x68, ACPI_GPE0_BLK & 0xFF);
52 pmio_write(0x69, ACPI_GPE0_BLK >> 8);
54 /* CpuControl is in \_PR.CPU0, 6 bytes */
55 pmio_write(0x66, ACPI_CPU_CONTROL & 0xFF);
56 pmio_write(0x67, ACPI_CPU_CONTROL >> 8);
58 pmio_write(0x6A, 0); /* AcpiSmiCmdLo */
59 pmio_write(0x6B, 0); /* AcpiSmiCmdHi */
61 pmio_write(0x6C, ACPI_PMA_CNT_BLK & 0xFF);
62 pmio_write(0x6D, ACPI_PMA_CNT_BLK >> 8);
64 pm_iowrite(0x74, 1<<0 | 1<<1 | 1<<4 | 1<<2); /* AcpiDecodeEnable, When set, SB uses
65 * the contents of the PM registers at
66 * index 60-6B to decode ACPI I/O address.
67 * AcpiSmiEn & SmiCmdEn*/
70 /* RPR 2.28 Get SB ASIC Revision.*/
71 static u8 get_sb800_revision(void)
77 /* if (rev != 0) return rev; */
79 dev = PCI_DEV(0, 0x14, 0);//pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
81 if (dev == PCI_DEV_INVALID) {
82 die("SMBUS controller not found\n");
85 rev_id = pci_read_config8(dev, 0x08);
89 } else if (rev_id == 0x41) {
92 die("It is not SB800 or SB810\r\n");
99 static void sb800_clk_output_48Mhz(void)
101 /* AcpiMMioDecodeEn */
103 reg8 = pmio_read(0x24);
106 pmio_write(0x24, reg8);
108 *(volatile u32 *)(0xFED80000+0xE00+0x40) &= ~((1 << 0) | (1 << 2)); /* 48Mhz */
109 *(volatile u32 *)(0xFED80000+0xE00+0x40) |= 1 << 1; /* 48Mhz */
112 /***************************************
113 * Legacy devices are mapped to LPC space.
116 * ACPI Micro-controller port
118 * This function does not change port 0x80 decoding.
119 * Console output through any port besides 0x3f8 is unsupported.
120 * If you use FWH ROMs, you have to setup IDSEL.
121 ***************************************/
122 static void sb800_lpc_init(void)
127 //dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0); /* SMBUS controller */
128 dev = PCI_DEV(0, 0x14, 0);
129 /* NOTE: Set BootTimerDisable, otherwise it would keep rebooting!!
130 * This bit has no meaning if debug strap is not enabled. So if the
131 * board keeps rebooting and the code fails to reach here, we could
132 * disable the debug strap first. */
133 reg8 = pmio_read(0x44+3);
135 pmio_write(0x44+3, reg8);
137 /* Enable lpc controller */
138 reg8 = pmio_read(0xEC);
140 pmio_write(0xEC, reg8);
142 dev = PCI_DEV(0, 0x14, 3);//pci_locate_device(PCI_ID(0x1002, 0x439d), 0); /* LPC Controller */
143 /* Decode port 0x3f8-0x3ff (Serial 0) */
144 //#warning Serial port decode on LPC is hardcoded to 0x3f8
145 reg8 = pci_read_config8(dev, 0x44);
147 pci_write_config8(dev, 0x44, reg8);
149 /* Decode port 0x60 & 0x64 (PS/2 keyboard) and port 0x62 & 0x66 (ACPI)*/
150 reg8 = pci_read_config8(dev, 0x47);
151 reg8 |= (1 << 5) | (1 << 6);
152 pci_write_config8(dev, 0x47, reg8);
154 /* SuperIO, LPC ROM */
155 reg8 = pci_read_config8(dev, 0x48);
156 /* Decode ports 0x2e-0x2f, 0x4e-0x4f (SuperI/O configuration) */
157 reg8 |= (1 << 1) | (1 << 0);
158 /* Decode variable LPC ROM address ranges 1&2 (see register 0x68-0x6b, 0x6c-0x6f) */
159 reg8 |= (1 << 3) | (1 << 4);
160 /* Decode port 0x70-0x73 (RTC) */
162 pci_write_config8(dev, 0x48, reg8);
165 /* what is its usage? */
166 static u32 get_sbdn(u32 bus)
170 /* Find the device. */
171 dev = PCI_DEV(bus, 0x14, 0);//pci_locate_device_on_bus(PCI_ID(0x1002, 0x4385), bus);
172 return (dev >> 15) & 0x1f;
175 static u8 dual_core(void)
177 return (pci_read_config32(PCI_DEV(0, 0x18, 3), 0xE8) & (0x3<<12)) != 0;
181 * RPR 2.6 C-state and VID/FID change for the K8 platform.
183 static void enable_fid_change_on_sb(u32 sbbusn, u32 sbdn)
186 byte = pmio_read(0x80);
188 byte |= 1 << 2 | 1 << 1;
192 pmio_write(0x80, byte);
194 byte = pmio_read(0x7E);
197 pmio_write(0x7E, byte);
199 pmio_write(0x94, 0x01);
201 byte = pmio_read(0x89);
203 pmio_write(0x89, byte);
205 byte = pmio_read(0x9b);
208 pmio_write(0x9b, byte);
210 pmio_write(0x99, 0x10);
212 pmio_write(0x9A, 0x00);
213 pmio_write(0x96, 0x10);
214 pmio_write(0x97, 0x00);
216 byte = pmio_read(0x81);
218 pmio_write(0x81, byte);
221 void hard_reset(void)
230 void soft_reset(void)
238 static void sb800_pci_port80(void)
244 dev = PCI_DEV(0, 0x14, 4);//pci_locate_device(PCI_ID(0x1002, 0x4384), 0);
246 /* Chip Control: Enable subtractive decoding */
247 byte = pci_read_config8(dev, 0x40);
249 pci_write_config8(dev, 0x40, byte);
251 /* Misc Control: Enable subtractive decoding if 0x40 bit 5 is set */
252 byte = pci_read_config8(dev, 0x4B);
254 pci_write_config8(dev, 0x4B, byte);
256 /* The same IO Base and IO Limit here is meaningful because we set the
257 * bridge to be subtractive. During early setup stage, we have to make
258 * sure that data can go through port 0x80.
260 /* IO Base: 0xf000 */
261 byte = pci_read_config8(dev, 0x1C);
263 pci_write_config8(dev, 0x1C, byte);
265 /* IO Limit: 0xf000 */
266 byte = pci_read_config8(dev, 0x1D);
268 pci_write_config8(dev, 0x1D, byte);
270 /* PCI Command: Enable IO response */
271 byte = pci_read_config8(dev, 0x04);
273 pci_write_config8(dev, 0x04, byte);
276 dev = PCI_DEV(0, 0x14, 3);;//pci_locate_device(PCI_ID(0x1002, 0x439D), 0);
278 byte = pci_read_config8(dev, 0x4A);
279 byte &= ~(1 << 5); /* disable lpc port 80 */
280 pci_write_config8(dev, 0x4A, byte);
283 #define BIT0 (1 << 0)
284 #define BIT1 (1 << 1)
285 #define BIT2 (1 << 2)
286 #define BIT3 (1 << 3)
287 #define BIT4 (1 << 4)
288 #define BIT5 (1 << 5)
289 #define BIT6 (1 << 6)
290 #define BIT7 (1 << 7)
297 struct pm_entry const pm_table[] =
300 {0xD2, 0xCF, BIT4 + BIT5},
303 {0x44 + 3, 0x7F, BIT7},
306 {0x00 + 2, 0xFF, 0x40},
307 {0x00 + 3, 0xFF, 0x08},
308 {0x34, 0xEF, BIT0 + BIT1},
310 {0x5B, 0xF9, BIT1 + BIT2},
311 {0x08, 0xFE, BIT2 + BIT4},
312 {0x08 + 1, 0xFF, BIT0},
313 {0x54, 0x00, BIT4 + BIT7},
314 {0x04 + 3, 0xFD, BIT1},
315 {0x74, 0xF6, BIT0 + BIT3},
318 {0xF8 + 1, 0x00, 0x27},
319 {0xF8 + 2, 0x00, 0x00},
321 {0xC0 + 2, 0xBF, 0x40},
324 {0x54 + 3, 0xFC, BIT0 + BIT1},
325 {0x54 + 2, 0x7F, BIT7},
326 {0x54 + 2, 0x7F, 0x00},
327 {0xC4, ~(BIT2 + BIT4), BIT2 + BIT4},
329 {0xC0 + 1, 0x04, 0x03},
332 {0xC2, ~(BIT4), BIT4},
333 {0x74, 0x00, BIT0 + BIT1 + BIT2 + BIT4},
334 {0xDE + 1, ~(BIT0 + BIT1), BIT0 + BIT1},
337 {0xBA + 1, ~BIT6, BIT6},
339 {0xED, ~(BIT0 + BIT1), 0},
342 // {0xFF, 0xFF, 0xFF},
346 static void sb800_lpc_port80(void)
351 /* Enable LPC controller */
352 byte = pmio_read(0xEC);
354 pmio_write(0xEC, byte);
356 /* Enable port 80 LPC decode in pci function 3 configuration space. */
357 dev = PCI_DEV(0, 0x14, 3);//pci_locate_device(PCI_ID(0x1002, 0x439D), 0);
358 byte = pci_read_config8(dev, 0x4a);
359 byte |= 1 << 5; /* enable port 80 */
360 pci_write_config8(dev, 0x4a, byte);
363 /* sbDevicesPorInitTable */
364 static void sb800_devices_por_init(void)
369 printk(BIOS_INFO, "sb800_devices_por_init()\n");
370 /* SMBus Device, BDF:0-20-0 */
371 printk(BIOS_INFO, "sb800_devices_por_init(): SMBus Device, BDF:0-20-0\n");
372 dev = PCI_DEV(0, 0x14, 0);//pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
374 if (dev == PCI_DEV_INVALID) {
375 die("SMBUS controller not found\n");
378 printk(BIOS_INFO, "SMBus controller enabled, sb revision is A%x\n",
379 get_sb800_revision());
381 /* sbPorAtStartOfTblCfg */
382 /* rpr 4.1.Set A-Link bridge access address.
383 * This is an I/O address. The I/O address must be on 16-byte boundry. */
384 //pci_write_config32(dev, 0xf0, AB_INDX);
385 pmio_write(0xE0, AB_INDX & 0xFF);
386 pmio_write(0xE1, (AB_INDX >> 8) & 0xFF);
387 pmio_write(0xE2, (AB_INDX >> 16) & 0xFF);
388 pmio_write(0xE3, (AB_INDX >> 24) & 0xFF);
390 /* To enable AB/BIF DMA access, a specific register inside the BIF register space needs to be configured first. */
391 /* 4.2:Enables the SB800 to send transactions upstream over A-Link Express interface. */
392 axcfg_reg(0x04, 1 << 2, 1 << 2);
393 //axindxc_reg(0x21, 0xff, 0);
395 /* 4.15:Enabling Non-Posted Memory Write for the K8 Platform */
396 axindxc_reg(0x10, 1 << 9, 1 << 9);
397 /* END of sbPorAtStartOfTblCfg */
399 /* sbDevicesPorInitTables */
400 /* set smbus iobase */
401 //pci_write_config32(dev, 0x90, SMBUS_IO_BASE | 1);
402 /* The base address of SMBUS is set in a different way with sb700. */
403 byte = (SMBUS_IO_BASE & 0xFF) | 1;
404 pmio_write(0x2c, byte & 0xFF);
405 pmio_write(0x2d, SMBUS_IO_BASE >> 8);
407 /* AcpiMMioDecodeEn */
408 byte = pmio_read(0x24);
411 pmio_write(0x24, byte);
412 /* enable smbus controller interface */
413 //byte = pci_read_config8(dev, 0xd2);
415 //pci_write_config8(dev, 0xd2, byte);
418 //pci_write_config8(dev, 0x40, 0x44);
420 /* Enable ISA Address 0-960K decoding */
421 //pci_write_config8(dev, 0x48, 0x0f);
423 /* Enable ISA Address 0xC0000-0xDFFFF decode */
424 //pci_write_config8(dev, 0x49, 0xff);
426 /* Enable decode cycles to IO C50, C51, C52 GPM controls. */
427 //byte = pci_read_config8(dev, 0x41);
430 //pci_write_config8(dev, 0x41, byte);
432 /* Legacy DMA Prefetch Enhancement, CIM masked it. */
433 /* pci_write_config8(dev, 0x43, 0x1); */
435 /* clear any lingering errors, so the transaction will run */
436 outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT);
438 /* IDE Device, BDF:0-20-1 */
439 printk(BIOS_INFO, "sb800_devices_por_init(): IDE Device, BDF:0-20-1\n");
440 dev = PCI_DEV(0, 0x14, 1);//pci_locate_device(PCI_ID(0x1002, 0x439C), 0);
441 /* Disable prefetch */
442 byte = pci_read_config8(dev, 0x63);
444 pci_write_config8(dev, 0x63, byte);
446 /* LPC Device, BDF:0-20-3 */
447 printk(BIOS_INFO, "sb800_devices_por_init(): LPC Device, BDF:0-20-3\n");
448 dev = PCI_DEV(0, 0x14, 3);//pci_locate_device(PCI_ID(0x1002, 0x439D), 0);
450 pci_write_config8(dev, 0x40, 0x04);
452 /* IO Port Decode Enable */
453 pci_write_config8(dev, 0x44, 0xFF);
454 pci_write_config8(dev, 0x45, 0xFF);
455 pci_write_config8(dev, 0x46, 0xC3);
456 pci_write_config8(dev, 0x47, 0xFF);
458 /* IO/Mem Port Decode Enable, I don't know why CIM disable some ports.
459 * Disable LPC TimeOut counter, enable SuperIO Configuration Port (2e/2f),
460 * Alternate SuperIO Configuration Port (4e/4f), Wide Generic IO Port (64/65).
461 * Enable bits for LPC ROM memory address range 1&2 for 1M ROM setting.*/
462 byte = pci_read_config8(dev, 0x48);
463 byte |= (1 << 1) | (1 << 0); /* enable Super IO config port 2e-2h, 4e-4f */
464 byte |= (1 << 3) | (1 << 4); /* enable for LPC ROM address range1&2, Enable 512KB rom access at 0xFFF80000 - 0xFFFFFFFF */
465 byte |= 1 << 6; /* enable for RTC I/O range */
466 pci_write_config8(dev, 0x48, byte);
467 pci_write_config8(dev, 0x49, 0xFF);
468 /* Enable 0x480-0x4bf, 0x4700-0x470B */
469 byte = pci_read_config8(dev, 0x4A);
470 byte |= ((1 << 1) + (1 << 6)); /*0x42, save the configuraion for port 0x80. */
471 pci_write_config8(dev, 0x4A, byte);
473 /* Set LPC ROM size, it has been done in sb800_lpc_init().
474 * enable LPC ROM range, 0xfff8: 512KB, 0xfff0: 1MB;
475 * enable LPC ROM range, 0xfff8: 512KB, 0xfff0: 1MB
476 * pci_write_config16(dev, 0x68, 0x000e)
477 * pci_write_config16(dev, 0x6c, 0xfff0);*/
479 /* Enable Tpm12_en and Tpm_legacy. I don't know what is its usage and copied from CIM. */
480 pci_write_config8(dev, 0x7C, 0x05);
482 /* P2P Bridge, BDF:0-20-4, the configuration of the registers in this dev are copied from CIM,
484 printk(BIOS_INFO, "sb800_devices_por_init(): P2P Bridge, BDF:0-20-4\n");
485 dev = PCI_DEV(0, 0x14, 4);//pci_locate_device(PCI_ID(0x1002, 0x4384), 0);
487 /* Arbiter enable. */
488 pci_write_config8(dev, 0x43, 0xff);
490 /* Set PCDMA request into hight priority list. */
491 /* pci_write_config8(dev, 0x49, 0x1) */ ;
493 pci_write_config8(dev, 0x40, 0x26);
495 pci_write_config8(dev, 0x0d, 0x40);
496 pci_write_config8(dev, 0x1b, 0x40);
497 /* Enable PCIB_DUAL_EN_UP will fix potential problem with PCI cards. */
498 pci_write_config8(dev, 0x50, 0x01);
500 /* SATA Device, BDF:0-17-0, Non-Raid-5 SATA controller */
501 printk(BIOS_INFO, "sb800_devices_por_init(): SATA Device, BDF:0-18-0\n");
502 dev = PCI_DEV(0, 0x11, 0);//pci_locate_device(PCI_ID(0x1002, 0x4390), 0);
504 /*PHY Global Control*/
505 pci_write_config16(dev, 0x86, 0x2C00);
508 /* sbPmioPorInitTable, Pre-initializing PMIO register space
509 * The power management (PM) block is resident in the PCI/LPC/ISA bridge.
510 * The PM regs are accessed via IO mapped regs 0xcd6 and 0xcd7.
511 * The index address is first programmed into IO reg 0xcd6.
512 * Read or write values are accessed through IO reg 0xcd7.
515 static void sb800_pmio_por_init(void)
519 printk(BIOS_INFO, "sb800_pmio_por_init()\n");
521 byte = pmio_read(0xD2);
523 pmio_write(0xD2, byte);
525 byte = pmio_read(0x5D);
528 pmio_write(0x5D, byte);
530 /* Watch Dog Timer Control
531 * Set watchdog time base to 0xfec000f0 to avoid SCSI card boot failure.
532 * But I don't find WDT is enabled in SMBUS 0x41 bit3 in CIM.
534 pmio_write(0x6c, 0xf0);
535 pmio_write(0x6d, 0x00);
536 pmio_write(0x6e, 0xc0);
537 pmio_write(0x6f, 0xfe);
539 /* rpr2.15: Enabling Spread Spectrum */
540 byte = pmio_read(0x42);
542 pmio_write(0x42, byte);
543 /* TODO: Check if it is necessary. IDE reset */
544 byte = pmio_read(0xB2);
546 pmio_write(0xB2, byte);
548 for (i=0; i<sizeof(pm_table)/sizeof(struct pm_entry); i++) {
549 byte = pmio_read(pm_table[i].port);
550 byte &= pm_table[i].mask;
551 byte |= pm_table[i].bit;
552 pmio_write(pm_table[i].port, byte);
554 pmio_write(0x00, 0x0E);
555 pmio_write(0x01, 0x00);
556 pmio_write(0x02, 0x4F);
557 pmio_write(0x03, 0x4A);
562 * Add any south bridge setting.
564 static void sb800_pci_cfg(void)
569 /* SMBus Device, BDF:0-20-0 */
570 dev = PCI_DEV(0, 0x14, 0);//pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
571 /* Enable watchdog decode timer */
572 byte = pci_read_config8(dev, 0x41);
574 pci_write_config8(dev, 0x41, byte);
576 /* Set to 1 to reset USB on the software (such as IO-64 or IO-CF9 cycles)
577 * generated PCIRST#. */
578 byte = pmio_read(0x65);
580 pmio_write(0x65, byte);
582 /* IDE Device, BDF:0-20-1 */
583 dev = PCI_DEV(0, 0x14, 1);//pci_locate_device(PCI_ID(0x1002, 0x439C), 0);
584 /* Enable IDE Explicit prefetch, 0x63[0] clear */
585 byte = pci_read_config8(dev, 0x63);
587 pci_write_config8(dev, 0x63, byte);
589 /* LPC Device, BDF:0-20-3 */
590 /* The code below is ported from old chipset. It is not
591 * metioned in RPR. But I keep them. The registers and the
592 * comments are compatible. */
593 dev = PCI_DEV(0, 0x14, 3);//pci_locate_device(PCI_ID(0x1002, 0x439D), 0);
594 /* Enabling LPC DMA function. */
595 byte = pci_read_config8(dev, 0x40);
597 pci_write_config8(dev, 0x40, byte);
598 /* Disabling LPC TimeOut. 0x48[7] clear. */
599 byte = pci_read_config8(dev, 0x48);
601 pci_write_config8(dev, 0x48, byte);
602 /* Disabling LPC MSI Capability, 0x78[1] clear. */
603 byte = pci_read_config8(dev, 0x78);
605 pci_write_config8(dev, 0x78, byte);
607 /* SATA Device, BDF:0-17-0, Non-Raid-5 SATA controller */
608 dev = PCI_DEV(0, 0x11, 0);//pci_locate_device(PCI_ID(0x1002, 0x4390), 0);
609 /* rpr7.12 SATA MSI and D3 Power State Capability. */
610 byte = pci_read_config8(dev, 0x40);
612 pci_write_config8(dev, 0x40, byte);
613 if (get_sb800_revision() <= 0x12)
614 pci_write_config8(dev, 0x34, 0x70); /* set 0x61 to 0x70 if S1 is not supported. */
616 pci_write_config8(dev, 0x34, 0x50); /* set 0x61 to 0x50 if S1 is not supported. */
618 pci_write_config8(dev, 0x40, byte);
623 static void sb800_por_init(void)
625 /* sbDevicesPorInitTable + sbK8PorInitTable */
626 sb800_devices_por_init();
628 /* sbPmioPorInitTable + sbK8PmioPorInitTable */
629 //sb800_pmio_por_init();
633 * It should be called during early POST after memory detection and BIOS shadowing but before PCI bus enumeration.
635 static void sb800_before_pci_init(void)
641 * This function should be called after enable_sb800_smbus().
643 static void sb800_early_setup(void)
645 printk(BIOS_INFO, "sb800_early_setup()\n");
650 static int smbus_read_byte(u32 device, u32 address)
652 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);