Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 2 | |
| 3 | #include <arch/io.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 4 | #include <device/pci_ops.h> |
Kyösti Mälkki | f555a58 | 2020-01-06 19:41:42 +0200 | [diff] [blame] | 5 | #include <device/smbus_host.h> |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 6 | #include "i82801ix.h" |
Arthur Heymans | 9ed0df4 | 2019-10-12 14:18:18 +0200 | [diff] [blame] | 7 | #include "chip.h" |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 8 | |
| 9 | void i82801ix_early_init(void) |
| 10 | { |
Antonello Dettori | 196e3d4 | 2016-09-01 17:04:14 +0200 | [diff] [blame] | 11 | const pci_devfn_t d31f0 = PCI_DEV(0, 0x1f, 0); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 12 | |
Kyösti Mälkki | 1cfafe2 | 2020-01-07 12:00:31 +0200 | [diff] [blame] | 13 | if (ENV_ROMSTAGE) |
| 14 | enable_smbus(); |
| 15 | |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 16 | /* Set up RCBA. */ |
Peter Lemenkov | 7b42811 | 2018-10-23 11:12:46 +0200 | [diff] [blame] | 17 | pci_write_config32(d31f0, RCBA, (uintptr_t)DEFAULT_RCBA | 1); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 18 | |
| 19 | /* Set up PMBASE. */ |
| 20 | pci_write_config32(d31f0, D31F0_PMBASE, DEFAULT_PMBASE | 1); |
| 21 | /* Enable PMBASE. */ |
| 22 | pci_write_config8(d31f0, D31F0_ACPI_CNTL, 0x80); |
| 23 | |
| 24 | /* Set up GPIOBASE. */ |
| 25 | pci_write_config32(d31f0, D31F0_GPIO_BASE, DEFAULT_GPIOBASE); |
| 26 | /* Enable GPIO. */ |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame^] | 27 | pci_or_config8(d31f0, D31F0_GPIO_CNTL, 0x10); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 28 | |
| 29 | /* Reset watchdog. */ |
| 30 | outw(0x0008, DEFAULT_TCOBASE + 0x04); /* R/WC, clear TCO caused SMI. */ |
| 31 | outw(0x0002, DEFAULT_TCOBASE + 0x06); /* R/WC, clear second timeout. */ |
| 32 | |
| 33 | /* Enable upper 128bytes of CMOS. */ |
| 34 | RCBA32(0x3400) = (1 << 2); |
| 35 | |
Martin Roth | 2ed0aa2 | 2016-01-05 20:58:58 -0700 | [diff] [blame] | 36 | /* Initialize power management initialization |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 37 | register early as it affects reboot behavior. */ |
| 38 | /* Bit 20 activates global reset of host and ME on cf9 writes of 0x6 |
| 39 | and 0xe (required if ME is disabled but present), bit 31 locks it. |
| 40 | The other bits are 'must write'. */ |
| 41 | u8 reg8 = pci_read_config8(d31f0, 0xac); |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame^] | 42 | |
| 43 | /* FIXME: It's a 8-bit variable!!! */ |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 44 | reg8 |= (1 << 31) | (1 << 30) | (1 << 20) | (3 << 8); |
| 45 | pci_write_config8(d31f0, 0xac, reg8); |
| 46 | |
| 47 | /* TODO: If RTC power failed, reset RTC state machine |
| 48 | (set, then reset RTC 0x0b bit7) */ |
| 49 | |
| 50 | /* TODO: Check power state bits in GEN_PMCON_2 (D31F0 0xa2) |
| 51 | before they get cleared. */ |
| 52 | } |
Arthur Heymans | 9ed0df4 | 2019-10-12 14:18:18 +0200 | [diff] [blame] | 53 | |
| 54 | void i82801ix_lpc_decode(void) |
| 55 | { |
| 56 | const pci_devfn_t d31f0 = PCI_DEV(0, 0x1f, 0); |
| 57 | const struct device *dev = pcidev_on_root(0x1f, 0); |
| 58 | const struct southbridge_intel_i82801ix_config *config = NULL; |
| 59 | |
| 60 | /* Configure serial IRQs.*/ |
| 61 | pci_write_config8(d31f0, D31F0_SERIRQ_CNTL, 0xd0); |
| 62 | /* |
| 63 | * Enable some common LPC IO ranges: |
| 64 | * - 0x2e/0x2f, 0x4e/0x4f often SuperIO |
| 65 | * - 0x60/0x64, 0x62/0x66 often KBC/EC |
| 66 | * - 0x3f0-0x3f5/0x3f7 FDD |
| 67 | * - 0x378-0x37f and 0x778-0x77f LPT |
| 68 | * - 0x2f8-0x2ff COMB |
| 69 | * - 0x3f8-0x3ff COMA |
Arthur Heymans | 21c9aa1 | 2019-11-20 12:24:25 +0100 | [diff] [blame] | 70 | * - 0x208-0x20f GAMEH |
| 71 | * - 0x200-0x207 GAMEL |
Arthur Heymans | 9ed0df4 | 2019-10-12 14:18:18 +0200 | [diff] [blame] | 72 | */ |
| 73 | pci_write_config16(d31f0, D31F0_LPC_IODEC, 0x0010); |
| 74 | pci_write_config16(d31f0, D31F0_LPC_EN, 0x3f0f); |
| 75 | |
| 76 | /* Set up generic decode ranges */ |
| 77 | if (!dev || !dev->chip_info) |
| 78 | return; |
| 79 | config = dev->chip_info; |
| 80 | |
| 81 | pci_write_config32(d31f0, D31F0_GEN1_DEC, config->gen1_dec); |
| 82 | pci_write_config32(d31f0, D31F0_GEN2_DEC, config->gen2_dec); |
| 83 | pci_write_config32(d31f0, D31F0_GEN3_DEC, config->gen3_dec); |
| 84 | pci_write_config32(d31f0, D31F0_GEN4_DEC, config->gen4_dec); |
| 85 | } |