Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 4 | #include <device/pci_ops.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 5 | #include <device/device.h> |
| 6 | #include <device/pci.h> |
Angel Pons | 2178b72 | 2020-05-31 00:55:35 +0200 | [diff] [blame] | 7 | #include "iobp.h" |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 8 | #include "pch.h" |
| 9 | |
Elyes HAOUAS | 1dcd8db | 2018-12-05 10:59:42 +0100 | [diff] [blame] | 10 | #ifdef __SIMPLE_DEVICE__ |
| 11 | static pci_devfn_t pch_get_lpc_device(void) |
Duncan Laurie | 5cc51c0 | 2013-03-07 14:06:43 -0800 | [diff] [blame] | 12 | { |
Duncan Laurie | 5cc51c0 | 2013-03-07 14:06:43 -0800 | [diff] [blame] | 13 | return PCI_DEV(0, 0x1f, 0); |
Duncan Laurie | 5cc51c0 | 2013-03-07 14:06:43 -0800 | [diff] [blame] | 14 | } |
Elyes HAOUAS | 1dcd8db | 2018-12-05 10:59:42 +0100 | [diff] [blame] | 15 | #else |
| 16 | static struct device *pch_get_lpc_device(void) |
| 17 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 18 | return pcidev_on_root(0x1f, 0); |
Elyes HAOUAS | 1dcd8db | 2018-12-05 10:59:42 +0100 | [diff] [blame] | 19 | } |
| 20 | #endif |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 21 | |
| 22 | int pch_silicon_revision(void) |
| 23 | { |
Duncan Laurie | 5cc51c0 | 2013-03-07 14:06:43 -0800 | [diff] [blame] | 24 | static int pch_revision_id = -1; |
| 25 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 26 | if (pch_revision_id < 0) |
Duncan Laurie | 5cc51c0 | 2013-03-07 14:06:43 -0800 | [diff] [blame] | 27 | pch_revision_id = pci_read_config8(pch_get_lpc_device(), |
| 28 | PCI_REVISION_ID); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 29 | return pch_revision_id; |
| 30 | } |
| 31 | |
Tristan Corrick | d3f01b2 | 2018-12-06 22:46:58 +1300 | [diff] [blame] | 32 | int pch_silicon_id(void) |
| 33 | { |
| 34 | static int pch_id = -1; |
| 35 | |
| 36 | if (pch_id < 0) |
| 37 | pch_id = pci_read_config16(pch_get_lpc_device(), PCI_DEVICE_ID); |
| 38 | |
| 39 | return pch_id; |
| 40 | } |
| 41 | |
Angel Pons | 3173993 | 2020-07-03 23:14:40 +0200 | [diff] [blame] | 42 | enum pch_platform_type get_pch_platform_type(void) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 43 | { |
Angel Pons | 3173993 | 2020-07-03 23:14:40 +0200 | [diff] [blame] | 44 | const u16 did = pci_read_config16(pch_get_lpc_device(), PCI_DEVICE_ID); |
Duncan Laurie | 5cc51c0 | 2013-03-07 14:06:43 -0800 | [diff] [blame] | 45 | |
Angel Pons | 3173993 | 2020-07-03 23:14:40 +0200 | [diff] [blame] | 46 | /* Check if this is a LPT-LP or WPT-LP device ID */ |
| 47 | if ((did & 0xff00) == 0x9c00) |
| 48 | return PCH_TYPE_ULT; |
| 49 | |
| 50 | /* Non-LP laptop SKUs have an odd device ID (least significant bit is one) */ |
| 51 | if (did & 1) |
| 52 | return PCH_TYPE_MOBILE; |
| 53 | |
| 54 | /* Desktop and Server SKUs have an even device ID */ |
| 55 | return PCH_TYPE_DESKTOP; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 56 | } |
| 57 | |
Duncan Laurie | 1ad5564 | 2013-03-07 14:08:04 -0800 | [diff] [blame] | 58 | u16 get_pmbase(void) |
| 59 | { |
| 60 | static u16 pmbase; |
| 61 | |
| 62 | if (!pmbase) |
| 63 | pmbase = pci_read_config16(pch_get_lpc_device(), |
| 64 | PMBASE) & 0xfffc; |
| 65 | return pmbase; |
| 66 | } |
| 67 | |
| 68 | u16 get_gpiobase(void) |
| 69 | { |
| 70 | static u16 gpiobase; |
| 71 | |
| 72 | if (!gpiobase) |
| 73 | gpiobase = pci_read_config16(pch_get_lpc_device(), |
| 74 | GPIOBASE) & 0xfffc; |
| 75 | return gpiobase; |
| 76 | } |
| 77 | |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 78 | #ifndef __SIMPLE_DEVICE__ |
Duncan Laurie | 5cc51c0 | 2013-03-07 14:06:43 -0800 | [diff] [blame] | 79 | |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 80 | /* Put device in D3Hot Power State */ |
Elyes HAOUAS | 38f1d13 | 2018-09-17 08:44:18 +0200 | [diff] [blame] | 81 | static void pch_enable_d3hot(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 82 | { |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 83 | pci_or_config32(dev, PCH_PCS, PCH_PCS_PS_D3HOT); |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Frans Hendriks | e6bf51f | 2019-05-01 10:48:31 +0200 | [diff] [blame] | 86 | /* Set bit in function disable register to hide this device */ |
Elyes HAOUAS | 38f1d13 | 2018-09-17 08:44:18 +0200 | [diff] [blame] | 87 | void pch_disable_devfn(struct device *dev) |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 88 | { |
| 89 | switch (dev->path.pci.devfn) { |
Duncan Laurie | 26e7dd7 | 2012-12-19 09:12:31 -0800 | [diff] [blame] | 90 | case PCI_DEVFN(19, 0): /* Audio DSP */ |
| 91 | RCBA32_OR(FD, PCH_DISABLE_ADSPD); |
| 92 | break; |
| 93 | case PCI_DEVFN(20, 0): /* XHCI */ |
| 94 | RCBA32_OR(FD, PCH_DISABLE_XHCI); |
| 95 | break; |
Duncan Laurie | 71346c0 | 2013-01-10 13:20:40 -0800 | [diff] [blame] | 96 | case PCI_DEVFN(21, 0): /* DMA */ |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 97 | pch_enable_d3hot(dev); |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 98 | pch_iobp_update(SIO_IOBP_FUNCDIS0, ~0, SIO_IOBP_FUNCDIS_DIS); |
Duncan Laurie | 71346c0 | 2013-01-10 13:20:40 -0800 | [diff] [blame] | 99 | break; |
| 100 | case PCI_DEVFN(21, 1): /* I2C0 */ |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 101 | pch_enable_d3hot(dev); |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 102 | pch_iobp_update(SIO_IOBP_FUNCDIS1, ~0, SIO_IOBP_FUNCDIS_DIS); |
Duncan Laurie | 71346c0 | 2013-01-10 13:20:40 -0800 | [diff] [blame] | 103 | break; |
| 104 | case PCI_DEVFN(21, 2): /* I2C1 */ |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 105 | pch_enable_d3hot(dev); |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 106 | pch_iobp_update(SIO_IOBP_FUNCDIS2, ~0, SIO_IOBP_FUNCDIS_DIS); |
Duncan Laurie | 71346c0 | 2013-01-10 13:20:40 -0800 | [diff] [blame] | 107 | break; |
| 108 | case PCI_DEVFN(21, 3): /* SPI0 */ |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 109 | pch_enable_d3hot(dev); |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 110 | pch_iobp_update(SIO_IOBP_FUNCDIS3, ~0, SIO_IOBP_FUNCDIS_DIS); |
Duncan Laurie | 71346c0 | 2013-01-10 13:20:40 -0800 | [diff] [blame] | 111 | break; |
| 112 | case PCI_DEVFN(21, 4): /* SPI1 */ |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 113 | pch_enable_d3hot(dev); |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 114 | pch_iobp_update(SIO_IOBP_FUNCDIS4, ~0, SIO_IOBP_FUNCDIS_DIS); |
Duncan Laurie | 71346c0 | 2013-01-10 13:20:40 -0800 | [diff] [blame] | 115 | break; |
| 116 | case PCI_DEVFN(21, 5): /* UART0 */ |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 117 | pch_enable_d3hot(dev); |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 118 | pch_iobp_update(SIO_IOBP_FUNCDIS5, ~0, SIO_IOBP_FUNCDIS_DIS); |
Duncan Laurie | 71346c0 | 2013-01-10 13:20:40 -0800 | [diff] [blame] | 119 | break; |
| 120 | case PCI_DEVFN(21, 6): /* UART1 */ |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 121 | pch_enable_d3hot(dev); |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 122 | pch_iobp_update(SIO_IOBP_FUNCDIS6, ~0, SIO_IOBP_FUNCDIS_DIS); |
Duncan Laurie | 71346c0 | 2013-01-10 13:20:40 -0800 | [diff] [blame] | 123 | break; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 124 | case PCI_DEVFN(22, 0): /* MEI #1 */ |
| 125 | RCBA32_OR(FD2, PCH_DISABLE_MEI1); |
| 126 | break; |
| 127 | case PCI_DEVFN(22, 1): /* MEI #2 */ |
| 128 | RCBA32_OR(FD2, PCH_DISABLE_MEI2); |
| 129 | break; |
| 130 | case PCI_DEVFN(22, 2): /* IDE-R */ |
| 131 | RCBA32_OR(FD2, PCH_DISABLE_IDER); |
| 132 | break; |
| 133 | case PCI_DEVFN(22, 3): /* KT */ |
| 134 | RCBA32_OR(FD2, PCH_DISABLE_KT); |
| 135 | break; |
Duncan Laurie | 71346c0 | 2013-01-10 13:20:40 -0800 | [diff] [blame] | 136 | case PCI_DEVFN(23, 0): /* SDIO */ |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 137 | pch_enable_d3hot(dev); |
Angel Pons | 8963f7d | 2020-10-24 12:20:28 +0200 | [diff] [blame] | 138 | pch_iobp_update(SIO_IOBP_FUNCDIS7, ~0, SIO_IOBP_FUNCDIS_DIS); |
Duncan Laurie | 71346c0 | 2013-01-10 13:20:40 -0800 | [diff] [blame] | 139 | break; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 140 | case PCI_DEVFN(25, 0): /* Gigabit Ethernet */ |
| 141 | RCBA32_OR(BUC, PCH_DISABLE_GBE); |
| 142 | break; |
| 143 | case PCI_DEVFN(26, 0): /* EHCI #2 */ |
| 144 | RCBA32_OR(FD, PCH_DISABLE_EHCI2); |
| 145 | break; |
| 146 | case PCI_DEVFN(27, 0): /* HD Audio Controller */ |
| 147 | RCBA32_OR(FD, PCH_DISABLE_HD_AUDIO); |
| 148 | break; |
| 149 | case PCI_DEVFN(28, 0): /* PCI Express Root Port 1 */ |
| 150 | case PCI_DEVFN(28, 1): /* PCI Express Root Port 2 */ |
| 151 | case PCI_DEVFN(28, 2): /* PCI Express Root Port 3 */ |
| 152 | case PCI_DEVFN(28, 3): /* PCI Express Root Port 4 */ |
| 153 | case PCI_DEVFN(28, 4): /* PCI Express Root Port 5 */ |
| 154 | case PCI_DEVFN(28, 5): /* PCI Express Root Port 6 */ |
| 155 | case PCI_DEVFN(28, 6): /* PCI Express Root Port 7 */ |
| 156 | case PCI_DEVFN(28, 7): /* PCI Express Root Port 8 */ |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 157 | RCBA32_OR(FD, PCH_DISABLE_PCIE(PCI_FUNC(dev->path.pci.devfn))); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 158 | break; |
| 159 | case PCI_DEVFN(29, 0): /* EHCI #1 */ |
| 160 | RCBA32_OR(FD, PCH_DISABLE_EHCI1); |
| 161 | break; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 162 | case PCI_DEVFN(31, 0): /* LPC */ |
| 163 | RCBA32_OR(FD, PCH_DISABLE_LPC); |
| 164 | break; |
| 165 | case PCI_DEVFN(31, 2): /* SATA #1 */ |
| 166 | RCBA32_OR(FD, PCH_DISABLE_SATA1); |
| 167 | break; |
| 168 | case PCI_DEVFN(31, 3): /* SMBUS */ |
| 169 | RCBA32_OR(FD, PCH_DISABLE_SMBUS); |
| 170 | break; |
Duncan Laurie | 26e7dd7 | 2012-12-19 09:12:31 -0800 | [diff] [blame] | 171 | case PCI_DEVFN(31, 5): /* SATA #2 */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 172 | RCBA32_OR(FD, PCH_DISABLE_SATA2); |
| 173 | break; |
| 174 | case PCI_DEVFN(31, 6): /* Thermal Subsystem */ |
| 175 | RCBA32_OR(FD, PCH_DISABLE_THERMAL); |
| 176 | break; |
| 177 | } |
| 178 | } |
| 179 | |
Elyes HAOUAS | 38f1d13 | 2018-09-17 08:44:18 +0200 | [diff] [blame] | 180 | void pch_enable(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 181 | { |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 182 | /* PCH PCIe Root Ports are handled in PCIe driver. */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 183 | if (PCI_SLOT(dev->path.pci.devfn) == PCH_PCIE_DEV_SLOT) |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 184 | return; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 185 | |
| 186 | if (!dev->enabled) { |
Elyes Haouas | 8b8ada6 | 2022-11-22 17:36:02 +0100 | [diff] [blame] | 187 | printk(BIOS_DEBUG, "%s: Disabling device\n", dev_path(dev)); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 188 | |
| 189 | /* Ensure memory, io, and bus master are all disabled */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 190 | pci_and_config16(dev, PCI_COMMAND, |
| 191 | ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO)); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 192 | |
Aaron Durbin | 3fcd356 | 2013-06-19 13:20:37 -0500 | [diff] [blame] | 193 | /* Disable this device if possible */ |
| 194 | pch_disable_devfn(dev); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 195 | } else { |
| 196 | /* Enable SERR */ |
Elyes HAOUAS | 73ae076 | 2020-04-28 10:13:05 +0200 | [diff] [blame] | 197 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_SERR); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
| 201 | struct chip_operations southbridge_intel_lynxpoint_ops = { |
| 202 | CHIP_NAME("Intel Series 8 (Lynx Point) Southbridge") |
| 203 | .enable_dev = pch_enable, |
| 204 | }; |
Duncan Laurie | 5cc51c0 | 2013-03-07 14:06:43 -0800 | [diff] [blame] | 205 | |
Kyösti Mälkki | 21d6a27 | 2019-11-05 18:50:38 +0200 | [diff] [blame] | 206 | #endif /* __SIMPLE_DEVICE__ */ |