2 * This file is part of the coreboot project.
4 * Copyright (C) 2008 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
22 #include "sb600_smbus.c"
24 #define SMBUS_IO_BASE 0x1000 /* Is it a temporary SMBus I/O base address? */
28 static void pmio_write(u8 reg, u8 value)
31 outb(value, PM_INDEX + 1);
34 static u8 pmio_read(u8 reg)
37 return inb(PM_INDEX + 1);
40 /* Get SB ASIC Revision.*/
41 static u8 get_sb600_revision(void)
44 dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
46 if (dev == PCI_DEV_INVALID) {
47 die("SMBUS controller not found\r\n");
50 return pci_read_config8(dev, 0x08);
54 /***************************************
55 * Legacy devices are mapped to LPC space.
58 * ACPI Micro-controller port
60 * This function does not change port 0x80 decoding.
61 * Console output through any port besides 0x3f8 is unsupported.
62 * If you use FWH ROMs, you have to setup IDSEL.
63 * NOTE: Call me ASAP, because I will reset LPC ROM size!
64 * Reviewed-by: Carl-Daniel Hailfinger
65 * Reviewed against AMD SB600 Register Reference Manual rev. 3.03, section 3.1
67 ***************************************/
68 static void sb600_lpc_init(void)
74 /* Enable lpc controller */
75 dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0); /* SMBUS controller */
76 reg32 = pci_read_config32(dev, 0x64);
78 pci_write_config32(dev, 0x64, reg32);
80 dev = pci_locate_device(PCI_ID(0x1002, 0x438d), 0); /* LPC Controller */
81 /* Decode port 0x3f8-0x3ff (Serial 0) */
82 #warning Serial port decode on LPC is hardcoded to 0x3f8
83 reg8 = pci_read_config8(dev, 0x44);
85 pci_write_config8(dev, 0x44, reg8);
87 /* Decode port 0x60 & 0x64 (PS/2 keyboard) and port 0x62 & 0x66 (ACPI)*/
88 reg8 = pci_read_config8(dev, 0x47);
89 reg8 |= (1 << 5) | (1 << 6);
90 pci_write_config8(dev, 0x47, reg8);
92 /* SuperIO, LPC ROM */
93 reg8 = pci_read_config8(dev, 0x48);
94 /* Decode ports 0x2e-0x2f, 0x4e-0x4f (SuperI/O configuration) */
95 reg8 |= (1 << 1) | (1 << 0);
96 /* Decode variable LPC ROM address ranges 1&2 (see register 0x68-0x6b, 0x6c-0x6f) */
97 reg8 |= (1 << 3) | (1 << 4);
98 /* Decode port 0x70-0x73 (RTC) */
100 pci_write_config8(dev, 0x48, reg8);
102 /* hardware should enable LPC ROM by pin straps */
103 /* ROM access at 0xFFF80000/0xFFF00000 - 0xFFFFFFFF */
104 /* See detail in BDG-215SB600-03.pdf page 15. */
105 /* enable LPC ROM range mirroring start 0x000e(0000) */
106 pci_write_config16(dev, 0x68, 0x000e);
107 /* enable LPC ROM range mirroring end 0x000f(ffff) */
108 pci_write_config16(dev, 0x6a, 0x000f);
109 /* enable LPC ROM range start, 0xfff8(0000): 512KB, 0xfff0(0000): 1MB */
110 pci_write_config16(dev, 0x6c, 0xfff0);
111 /* enable LPC ROM range end at 0xffff(ffff) */
112 pci_write_config16(dev, 0x6e, 0xffff);
115 /* what is its usage? */
116 static u32 get_sbdn(u32 bus)
120 /* Find the device. */
121 dev = pci_locate_device_on_bus(PCI_ID(0x1002, 0x4385), bus);
122 return (dev >> 15) & 0x1f;
126 static u8 dual_core(void)
128 return (pci_read_config32(PCI_DEV(0, 0x18, 3), 0xE8) & (0x3<<12)) != 0;
132 SB600 VFSMAF (VID/FID System Management Action Field) is 010b by default.
133 RPR 2.3.3 C-state and VID/FID change for the K8 platform.
135 static void enable_fid_change_on_sb(u32 sbbusn, u32 sbdn)
138 byte = pmio_read(0x9a);
144 pmio_write(0x9a, byte);
146 byte = pmio_read(0x8f);
149 pmio_write(0x8f, byte);
151 pmio_write(0x8b, 0x01);
152 pmio_write(0x8a, 0x90);
154 if(get_sb600_revision() > 0x13)
155 pmio_write(0x88, 0x10);
157 pmio_write(0x88, 0x06);
159 byte = pmio_read(0x7c);
162 pmio_write(0x7c, byte);
164 /*Must be 0 for K8 platform.*/
165 byte = pmio_read(0x68);
167 pmio_write(0x68, byte);
168 /*Must be 0 for K8 platform.*/
169 byte = pmio_read(0x8d);
171 pmio_write(0x8d, byte);
173 byte = pmio_read(0x61);
175 pmio_write(0x61, byte);
177 byte = pmio_read(0x42);
179 pmio_write(0x42, byte);
181 if(get_sb600_revision() == 0x14) {
182 pmio_write(0x89, 0x10);
184 byte = pmio_read(0x52);
186 pmio_write(0x52, byte);
191 static void hard_reset(void)
200 static void soft_reset(void)
208 static void sb600_pci_port80(void)
214 dev = pci_locate_device(PCI_ID(0x1002, 0x4384), 0);
216 /* Chip Control: Enable subtractive decoding */
217 byte = pci_read_config8(dev, 0x40);
219 pci_write_config8(dev, 0x40, byte);
221 /* Misc Control: Enable subtractive decoding if 0x40 bit 5 is set */
222 byte = pci_read_config8(dev, 0x4B);
224 pci_write_config8(dev, 0x4B, byte);
226 /* The same IO Base and IO Limit here is meaningful because we set the
227 * bridge to be subtractive. During early setup stage, we have to make
228 * sure that data can go through port 0x80.
230 /* IO Base: 0xf000 */
231 byte = pci_read_config8(dev, 0x1C);
233 pci_write_config8(dev, 0x1C, byte);
235 /* IO Limit: 0xf000 */
236 byte = pci_read_config8(dev, 0x1D);
238 pci_write_config8(dev, 0x1D, byte);
240 /* PCI Command: Enable IO response */
241 byte = pci_read_config8(dev, 0x04);
243 pci_write_config8(dev, 0x04, byte);
246 dev = pci_locate_device(PCI_ID(0x1002, 0x438D), 0);
248 byte = pci_read_config8(dev, 0x4A);
249 byte &= ~(1 << 5); /* disable lpc port 80 */
250 pci_write_config8(dev, 0x4A, byte);
253 static void sb600_lpc_port80(void)
259 /* Enable LPC controller */
260 dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
261 reg32 = pci_read_config32(dev, 0x64);
262 reg32 |= 0x00100000; /* lpcEnable */
263 pci_write_config32(dev, 0x64, reg32);
265 /* Enable port 80 LPC decode in pci function 3 configuration space. */
266 dev = pci_locate_device(PCI_ID(0x1002, 0x438d), 0);
267 byte = pci_read_config8(dev, 0x4a);
268 byte |= 1 << 5; /* enable port 80 */
269 pci_write_config8(dev, 0x4a, byte);
273 /* sbDevicesPorInitTable */
274 static void sb600_devices_por_init(void)
279 printk_info("sb600_devices_por_init()\n");
280 /* SMBus Device, BDF:0-20-0 */
281 printk_info("sb600_devices_por_init(): SMBus Device, BDF:0-20-0\n");
282 dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
284 if (dev == PCI_DEV_INVALID) {
285 die("SMBUS controller not found\r\n");
288 printk_info("SMBus controller enabled, sb revision is 0x%x\r\n",
289 get_sb600_revision());
291 /* sbPorAtStartOfTblCfg */
292 /* Set A-Link bridge access address. This address is set at device 14h, function 0, register 0xf0.
293 * This is an I/O address. The I/O address must be on 16-byte boundry. */
294 pci_write_config32(dev, 0xf0, AB_INDX);
296 /* To enable AB/BIF DMA access, a specific register inside the BIF register space needs to be configured first. */
297 /*Enables the SB600 to send transactions upstream over A-Link Express interface. */
298 axcfg_reg(0x04, 1 << 2, 1 << 2);
299 axindxc_reg(0x21, 0xff, 0);
301 /* 2.3.5:Enabling Non-Posted Memory Write for the K8 Platform */
302 axindxc_reg(0x10, 1 << 9, 1 << 9);
303 /* END of sbPorAtStartOfTblCfg */
305 /* sbDevicesPorInitTables */
306 /* set smbus iobase */
307 pci_write_config32(dev, 0x10, SMBUS_IO_BASE | 1);
309 /* enable smbus controller interface */
310 byte = pci_read_config8(dev, 0xd2);
312 pci_write_config8(dev, 0xd2, byte);
314 /* set smbus 1, ASF 2.0 (Alert Standard Format), iobase */
315 pci_write_config16(dev, 0x58, SMBUS_IO_BASE | 0x11);
317 /* TODO: I don't know the useage of followed two lines. I copied them from CIM. */
318 pci_write_config8(dev, 0x0a, 0x1);
319 pci_write_config8(dev, 0x0b, 0x6);
322 pci_write_config8(dev, 0x40, 0xd4);
324 /* Enable ISA Address 0-960K decoding */
325 pci_write_config8(dev, 0x48, 0x0f);
327 /* Enable ISA Address 0xC0000-0xDFFFF decode */
328 pci_write_config8(dev, 0x49, 0xff);
330 /* Enable decode cycles to IO C50, C51, C52 GPM controls. */
331 byte = pci_read_config8(dev, 0x41);
334 pci_write_config8(dev, 0x41, byte);
336 /* Legacy DMA Prefetch Enhancement, CIM masked it. */
337 /* pci_write_config8(dev, 0x43, 0x1); */
339 /* Disabling Legacy USB Fast SMI# */
340 byte = pci_read_config8(dev, 0x62);
342 pci_write_config8(dev, 0x62, byte);
344 /* Features Enable */
345 pci_write_config32(dev, 0x64, 0x829E7DBF); /* bit10: Enables the HPET interrupt. */
347 /* SerialIrq Control */
348 pci_write_config8(dev, 0x69, 0x90);
350 /* Test Mode, PCIB_SReset_En Mask is set. */
351 pci_write_config8(dev, 0x6c, 0x20);
353 /* IO Address Enable, CIM set 0x78 only and masked 0x79. */
354 /*pci_write_config8(dev, 0x79, 0x4F); */
355 pci_write_config8(dev, 0x78, 0xFF);
357 /* This register is not used on sb600. It came from older chipset. */
358 /*pci_write_config8(dev, 0x95, 0xFF); */
360 /* Set smbus iospace enable, I don't know why write 0x04 into reg5 that is reserved */
361 pci_write_config16(dev, 0x4, 0x0407);
363 /* clear any lingering errors, so the transaction will run */
364 outb(inb(SMBUS_IO_BASE + SMBHSTSTAT), SMBUS_IO_BASE + SMBHSTSTAT);
366 /* IDE Device, BDF:0-20-1 */
367 printk_info("sb600_devices_por_init(): IDE Device, BDF:0-20-1\n");
368 dev = pci_locate_device(PCI_ID(0x1002, 0x438C), 0);
369 /* Disable prefetch */
370 byte = pci_read_config8(dev, 0x63);
372 pci_write_config8(dev, 0x63, byte);
374 /* LPC Device, BDF:0-20-3 */
375 printk_info("sb600_devices_por_init(): LPC Device, BDF:0-20-3\n");
376 dev = pci_locate_device(PCI_ID(0x1002, 0x438D), 0);
378 pci_write_config8(dev, 0x40, 0x04);
380 /* IO Port Decode Enable */
381 pci_write_config8(dev, 0x44, 0xFF);
382 pci_write_config8(dev, 0x45, 0xFF);
383 pci_write_config8(dev, 0x46, 0xC3);
384 pci_write_config8(dev, 0x47, 0xFF);
386 /* IO/Mem Port Decode Enable, I don't know why CIM disable some ports.
387 * Disable LPC TimeOut counter, enable SuperIO Configuration Port (2e/2f),
388 * Alternate SuperIO Configuration Port (4e/4f), Wide Generic IO Port (64/65).
389 * Enable bits for LPC ROM memory address range 1&2 for 1M ROM setting.*/
390 byte = pci_read_config8(dev, 0x48);
391 byte |= (1 << 1) | (1 << 0); /* enable Super IO config port 2e-2h, 4e-4f */
392 byte |= (1 << 3) | (1 << 4); /* enable for LPC ROM address range1&2, Enable 512KB rom access at 0xFFF80000 - 0xFFFFFFFF */
393 byte |= 1 << 6; /* enable for RTC I/O range */
394 pci_write_config8(dev, 0x48, byte);
395 pci_write_config8(dev, 0x49, 0xFF);
396 /* Enable 0x480-0x4bf, 0x4700-0x470B */
397 byte = pci_read_config8(dev, 0x4A);
398 byte |= ((1 << 1) + (1 << 6)); /*0x42, save the configuraion for port 0x80. */
399 pci_write_config8(dev, 0x4A, byte);
401 /* Set LPC ROM size, it has been done in sb600_lpc_init().
402 * enable LPC ROM range, 0xfff8: 512KB, 0xfff0: 1MB;
403 * enable LPC ROM range, 0xfff8: 512KB, 0xfff0: 1MB
404 * pci_write_config16(dev, 0x68, 0x000e)
405 * pci_write_config16(dev, 0x6c, 0xfff0);*/
407 /* Enable Tpm12_en and Tpm_legacy. I don't know what is its usage and copied from CIM. */
408 pci_write_config8(dev, 0x7C, 0x05);
410 /* P2P Bridge, BDF:0-20-4, the configuration of the registers in this dev are copied from CIM,
411 * TODO: I don't know what are their mean? */
412 printk_info("sb600_devices_por_init(): P2P Bridge, BDF:0-20-4\n");
413 dev = pci_locate_device(PCI_ID(0x1002, 0x4384), 0);
414 /* I don't know why CIM tried to write into a read-only reg! */
415 /*pci_write_config8(dev, 0x0c, 0x20) */ ;
417 /* Arbiter enable. */
418 pci_write_config8(dev, 0x43, 0xff);
420 /* Set PCDMA request into hight priority list. */
421 /* pci_write_config8(dev, 0x49, 0x1) */ ;
423 pci_write_config8(dev, 0x40, 0x26);
425 /* I don't know why CIM set reg0x1c as 0x11.
426 * System will block at sdram_initialize() if I set it before call sdram_initialize().
427 * If it is necessary to set reg0x1c as 0x11, please call this function after sdram_initialize().
428 * pci_write_config8(dev, 0x1c, 0x11);
429 * pci_write_config8(dev, 0x1d, 0x11);*/
431 /*CIM set this register; but I didn't find its description in RPR.
432 On DBM690T platform, I didn't find different between set and skip this register.
433 But on Filbert platform, the CONFIG_DEBUG message from serial port on Peanut board can't be displayed
434 after the bit0 of this register is set.
435 pci_write_config8(dev, 0x04, 0x21);
437 pci_write_config8(dev, 0x0d, 0x40);
438 pci_write_config8(dev, 0x1b, 0x40);
439 /* Enable PCIB_DUAL_EN_UP will fix potential problem with PCI cards. */
440 pci_write_config8(dev, 0x50, 0x01);
442 /* SATA Device, BDF:0-18-0, Non-Raid-5 SATA controller */
443 printk_info("sb600_devices_por_init(): SATA Device, BDF:0-18-0\n");
444 dev = pci_locate_device(PCI_ID(0x1002, 0x4380), 0);
446 /*PHY Global Control, we are using A14.
447 * default: 0x2c40 for ASIC revision A12 and below
448 * 0x2c00 for ASIC revision A13 and above.*/
449 pci_write_config16(dev, 0x86, 0x2C00);
451 /* PHY Port0-3 Control */
452 pci_write_config32(dev, 0x88, 0xB400DA);
453 pci_write_config32(dev, 0x8c, 0xB400DA);
454 pci_write_config32(dev, 0x90, 0xB400DA);
455 pci_write_config32(dev, 0x94, 0xB400DA);
457 /* Port0-3 BIST Control/Status */
458 pci_write_config8(dev, 0xa5, 0xB8);
459 pci_write_config8(dev, 0xad, 0xB8);
460 pci_write_config8(dev, 0xb5, 0xB8);
461 pci_write_config8(dev, 0xbd, 0xB8);
464 /* sbPmioPorInitTable, Pre-initializing PMIO register space
465 * The power management (PM) block is resident in the PCI/LPC/ISA bridge.
466 * The PM regs are accessed via IO mapped regs 0xcd6 and 0xcd7.
467 * The index address is first programmed into IO reg 0xcd6.
468 * Read or write values are accessed through IO reg 0xcd7.
470 static void sb600_pmio_por_init(void)
474 printk_info("sb600_pmio_por_init()\n");
475 /* K8KbRstEn, KB_RST# control for K8 system. */
476 byte = pmio_read(0x66);
478 pmio_write(0x66, byte);
480 /* RPR2.3.4 S3/S4/S5 Function for the K8 Platform. */
481 byte = pmio_read(0x52);
484 pmio_write(0x52, byte);
486 /* C state enable and SLP enable in C states. */
487 byte = pmio_read(0x67);
489 pmio_write(0x67, byte);
491 /* CIM sets 0x0e, but bit2 is for P4 system. */
492 byte = pmio_read(0x68);
495 pmio_write(0x68, byte);
497 /* Watch Dog Timer Control
498 * Set watchdog time base to 0xfec000f0 to avoid SCSI card boot failure.
499 * But I don't find WDT is enabled in SMBUS 0x41 bit3 in CIM.
501 pmio_write(0x6c, 0xf0);
502 pmio_write(0x6d, 0x00);
503 pmio_write(0x6e, 0xc0);
504 pmio_write(0x6f, 0xfe);
506 /* rpr2.14: Enables HPET periodical mode */
507 byte = pmio_read(0x9a);
509 pmio_write(0x9a, byte);
510 byte = pmio_read(0x9f);
512 pmio_write(0x9f, byte);
513 byte = pmio_read(0x9e);
514 byte |= (1 << 6) | (1 << 7);
515 pmio_write(0x9e, byte);
517 /* rpr2.14: Hides SM bus controller Bar1 where stores HPET MMIO base address */
518 /* We have to clear this bit here, otherwise the kernel hangs. */
519 byte = pmio_read(0x55);
522 pmio_write(0x55, byte);
524 /* rpr2.14: Make HPET MMIO decoding controlled by the memory enable bit in command register of LPC ISA bridage */
525 byte = pmio_read(0x52);
527 pmio_write(0x52, byte);
529 /* rpr2.22: PLL Reset */
530 byte = pmio_read(0x86);
532 pmio_write(0x86, byte);
535 /* This provides 16us delay before the assertion of LDTSTP# when C3 is entered.
536 * The delay will allow USB DMA to go on in a continuous manner
538 pmio_write(0x89, 0x10);
539 /* Set this bit to allow pop-up request being latched during the minimum LDTSTP# assertion time */
540 byte = pmio_read(0x52);
542 pmio_write(0x52, byte);
544 /* rpr2.15: ASF Remote Control Action */
545 byte = pmio_read(0x9f);
547 pmio_write(0x9f, byte);
549 /* rpr2.19: Enabling Spread Spectrum */
550 byte = pmio_read(0x42);
552 pmio_write(0x42, byte);
556 * Compliant with CIM_48's sbPciCfg.
557 * Add any south bridge setting.
559 static void sb600_pci_cfg(void)
564 /* SMBus Device, BDF:0-20-0 */
565 dev = pci_locate_device(PCI_ID(0x1002, 0x4385), 0);
566 /* Eable the hidden revision ID, available after A13. */
567 byte = pci_read_config8(dev, 0x70);
569 pci_write_config8(dev, 0x70, byte);
570 /* rpr2.20 Disable Timer IRQ Enhancement for proper operation of the 8254 timer, 0xae[5]. */
571 byte = pci_read_config8(dev, 0xae);
573 pci_write_config8(dev, 0xae, byte);
575 /* Enable watchdog decode timer */
576 byte = pci_read_config8(dev, 0x41);
578 pci_write_config8(dev, 0x41, byte);
580 /* Set to 1 to reset USB on the software (such as IO-64 or IO-CF9 cycles)
581 * generated PCIRST#. */
582 byte = pmio_read(0x65);
584 pmio_write(0x65, byte);
585 /*For A13 and above. */
586 if (get_sb600_revision() > 0x12) {
587 /* rpr2.16 C-State Reset, PMIO 0x9f[7]. */
588 byte = pmio_read(0x9f);
590 pmio_write(0x9f, byte);
591 /* rpr2.17 PCI Clock Period will increase to 30.8ns. 0x53[7]. */
592 byte = pmio_read(0x53);
594 pmio_write(0x53, byte);
597 /* IDE Device, BDF:0-20-1 */
598 dev = pci_locate_device(PCI_ID(0x1002, 0x438C), 0);
599 /* Enable IDE Explicit prefetch, 0x63[0] clear */
600 byte = pci_read_config8(dev, 0x63);
602 pci_write_config8(dev, 0x63, byte);
604 /* LPC Device, BDF:0-20-3 */
605 dev = pci_locate_device(PCI_ID(0x1002, 0x438D), 0);
606 /* rpr7.2 Enabling LPC DMA function. */
607 byte = pci_read_config8(dev, 0x40);
609 pci_write_config8(dev, 0x40, byte);
610 /* rpr7.3 Disabling LPC TimeOut. 0x48[7] clear. */
611 byte = pci_read_config8(dev, 0x48);
613 pci_write_config8(dev, 0x48, byte);
614 /* rpr7.5 Disabling LPC MSI Capability, 0x78[1] clear. */
615 byte = pci_read_config8(dev, 0x78);
617 pci_write_config8(dev, 0x78, byte);
619 /* SATA Device, BDF:0-18-0, Non-Raid-5 SATA controller */
620 dev = pci_locate_device(PCI_ID(0x1002, 0x4380), 0);
621 /* rpr6.8 Disabling SATA MSI Capability, for A13 and above, 0x42[7]. */
622 if (0x12 < get_sb600_revision()) {
624 reg32 = pci_read_config32(dev, 0x40);
626 pci_write_config32(dev, 0x40, reg32);
629 /* EHCI Device, BDF:0-19-5, ehci usb controller */
630 dev = pci_locate_device(PCI_ID(0x1002, 0x4386), 0);
631 /* rpr5.10 Disabling USB EHCI MSI Capability. 0x50[6]. */
632 byte = pci_read_config8(dev, 0x50);
634 pci_write_config8(dev, 0x50, byte);
636 /* OHCI0 Device, BDF:0-19-0, ohci usb controller #0 */
637 dev = pci_locate_device(PCI_ID(0x1002, 0x4387), 0);
638 /* rpr5.11 Disabling USB OHCI MSI Capability. 0x40[12:8]=0x1f. */
639 byte = pci_read_config8(dev, 0x41);
641 pci_write_config8(dev, 0x41, byte);
646 * Compliant with CIM_48's ATSBPowerOnResetInitJSP
648 static void sb600_por_init(void)
650 /* sbDevicesPorInitTable + sbK8PorInitTable */
651 sb600_devices_por_init();
653 /* sbPmioPorInitTable + sbK8PmioPorInitTable */
654 sb600_pmio_por_init();
658 * Compliant with CIM_48's AtiSbBeforePciInit
659 * It should be called during early POST after memory detection and BIOS shadowing but before PCI bus enumeration.
661 static void sb600_before_pci_init(void)
667 * This function should be called after enable_sb600_smbus().
669 static void sb600_early_setup(void)
671 printk_info("sb600_early_setup()\n");
675 static int smbus_read_byte(u32 device, u32 address)
677 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);