Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 2 | |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 3 | #include <device/mmio.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 | 5daa1d3 | 2020-06-14 12:01:58 +0300 | [diff] [blame] | 5 | #include <acpi/acpi_gnvs.h> |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 6 | #include <console/console.h> |
| 7 | #include <device/device.h> |
| 8 | #include <device/pci.h> |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 9 | #include <device/pci_ids.h> |
Kyösti Mälkki | 661ad46 | 2020-12-29 06:26:21 +0200 | [diff] [blame] | 10 | #include <soc/nvs.h> |
Kyösti Mälkki | 12b121c | 2019-08-18 16:33:39 +0300 | [diff] [blame] | 11 | #include "chip.h" |
Angel Pons | 2178b72 | 2020-05-31 00:55:35 +0200 | [diff] [blame] | 12 | #include "iobp.h" |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 13 | #include "pch.h" |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 14 | |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 15 | /* Enable clock in PCI mode */ |
| 16 | static void serialio_enable_clock(struct resource *bar0) |
| 17 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 18 | u32 reg32 = read32(res2mmio(bar0, SIO_REG_PPR_CLOCK, 0)); |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 19 | reg32 |= SIO_REG_PPR_CLOCK_EN; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 20 | write32(res2mmio(bar0, SIO_REG_PPR_CLOCK, 0), reg32); |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 21 | } |
| 22 | |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 23 | /* Put Serial IO D21:F0-F6 device into desired mode. */ |
| 24 | static void serialio_d21_mode(int sio_index, int int_pin, int acpi_mode) |
| 25 | { |
| 26 | u32 portctrl = SIO_IOBP_PORTCTRL_PM_CAP_PRSNT; |
| 27 | |
| 28 | /* Snoop select 1. */ |
| 29 | portctrl |= SIO_IOBP_PORTCTRL_SNOOP_SELECT(1); |
| 30 | |
| 31 | /* Set interrupt pin. */ |
| 32 | portctrl |= SIO_IOBP_PORTCTRL_INT_PIN(int_pin); |
| 33 | |
| 34 | if (acpi_mode) { |
| 35 | /* Enable ACPI interrupt mode. */ |
| 36 | portctrl |= SIO_IOBP_PORTCTRL_ACPI_IRQ_EN; |
| 37 | |
| 38 | /* Disable PCI config space. */ |
| 39 | portctrl |= SIO_IOBP_PORTCTRL_PCI_CONF_DIS; |
| 40 | } |
| 41 | |
| 42 | pch_iobp_update(SIO_IOBP_PORTCTRLX(sio_index), 0, portctrl); |
| 43 | } |
| 44 | |
| 45 | /* Put Serial IO D23:F0 device into desired mode. */ |
| 46 | static void serialio_d23_mode(int acpi_mode) |
| 47 | { |
| 48 | u32 portctrl = 0; |
| 49 | |
| 50 | /* Snoop select 1. */ |
| 51 | pch_iobp_update(SIO_IOBP_PORTCTRL1, 0, |
| 52 | SIO_IOBP_PORTCTRL1_SNOOP_SELECT(1)); |
| 53 | |
| 54 | if (acpi_mode) { |
| 55 | /* Enable ACPI interrupt mode. */ |
| 56 | portctrl |= SIO_IOBP_PORTCTRL0_ACPI_IRQ_EN; |
| 57 | |
| 58 | /* Disable PCI config space. */ |
| 59 | portctrl |= SIO_IOBP_PORTCTRL0_PCI_CONF_DIS; |
| 60 | } |
| 61 | |
| 62 | pch_iobp_update(SIO_IOBP_PORTCTRL0, 0, portctrl); |
| 63 | } |
| 64 | |
| 65 | /* Enable LTR Auto Mode for D21:F1-F6. */ |
| 66 | static void serialio_d21_ltr(struct resource *bar0) |
| 67 | { |
| 68 | u32 reg; |
| 69 | |
| 70 | /* 1. Program BAR0 + 808h[2] = 0b */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 71 | reg = read32(res2mmio(bar0, SIO_REG_PPR_GEN, 0)); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 72 | reg &= ~SIO_REG_PPR_GEN_LTR_MODE_MASK; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 73 | write32(res2mmio(bar0, SIO_REG_PPR_GEN, 0), reg); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 74 | |
| 75 | /* 2. Program BAR0 + 804h[1:0] = 00b */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 76 | reg = read32(res2mmio(bar0, SIO_REG_PPR_RST, 0)); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 77 | reg &= ~SIO_REG_PPR_RST_ASSERT; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 78 | write32(res2mmio(bar0, SIO_REG_PPR_RST, 0), reg); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 79 | |
| 80 | /* 3. Program BAR0 + 804h[1:0] = 11b */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 81 | reg = read32(res2mmio(bar0, SIO_REG_PPR_RST, 0)); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 82 | reg |= SIO_REG_PPR_RST_ASSERT; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 83 | write32(res2mmio(bar0, SIO_REG_PPR_RST, 0), reg); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 84 | |
| 85 | /* 4. Program BAR0 + 814h[31:0] = 00000000h */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 86 | write32(res2mmio(bar0, SIO_REG_AUTO_LTR, 0), 0); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /* Enable LTR Auto Mode for D23:F0. */ |
| 90 | static void serialio_d23_ltr(struct resource *bar0) |
| 91 | { |
| 92 | u32 reg; |
| 93 | |
| 94 | /* Program BAR0 + 1008h[2] = 1b */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 95 | reg = read32(res2mmio(bar0, SIO_REG_SDIO_PPR_GEN, 0)); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 96 | reg |= SIO_REG_PPR_GEN_LTR_MODE_MASK; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 97 | write32(res2mmio(bar0, SIO_REG_SDIO_PPR_GEN, 0), reg); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 98 | |
| 99 | /* Program BAR0 + 1010h = 0x00000000 */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 100 | write32(res2mmio(bar0, SIO_REG_SDIO_PPR_SW_LTR, 0), 0); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 101 | |
| 102 | /* Program BAR0 + 3Ch[30] = 1b */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 103 | reg = read32(res2mmio(bar0, SIO_REG_SDIO_PPR_CMD12, 0)); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 104 | reg |= SIO_REG_SDIO_PPR_CMD12_B30; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 105 | write32(res2mmio(bar0, SIO_REG_SDIO_PPR_CMD12, 0), reg); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /* Select I2C voltage of 1.8V or 3.3V. */ |
| 109 | static void serialio_i2c_voltage_sel(struct resource *bar0, u8 voltage) |
| 110 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 111 | u32 reg32 = read32(res2mmio(bar0, SIO_REG_PPR_GEN, 0)); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 112 | reg32 &= ~SIO_REG_PPR_GEN_VOLTAGE_MASK; |
| 113 | reg32 |= SIO_REG_PPR_GEN_VOLTAGE(voltage); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 114 | write32(res2mmio(bar0, SIO_REG_PPR_GEN, 0), reg32); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /* Init sequence to be run once, done as part of D21:F0 (SDMA) init. */ |
| 118 | static void serialio_init_once(int acpi_mode) |
| 119 | { |
| 120 | if (acpi_mode) { |
| 121 | /* Enable ACPI IRQ for IRQ13, IRQ7, IRQ6, IRQ5 in RCBA. */ |
Angel Pons | 84fa224 | 2020-10-24 11:53:47 +0200 | [diff] [blame] | 122 | RCBA32_OR(ACPIIRQEN, (1 << 13) | (1 << 7) | (1 << 6) | (1 << 5)); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /* Program IOBP CB000154h[12,9:8,4:0] = 1001100011111b. */ |
| 126 | pch_iobp_update(SIO_IOBP_GPIODF, ~0x0000131f, 0x0000131f); |
| 127 | |
| 128 | /* Program IOBP CB000180h[5:0] = 111111b (undefined register) */ |
| 129 | pch_iobp_update(0xcb000180, ~0x0000003f, 0x0000003f); |
| 130 | } |
| 131 | |
Kyösti Mälkki | 5e82d44 | 2020-12-22 11:31:39 +0200 | [diff] [blame] | 132 | static void update_bars(int sio_index, u32 bar0, u32 bar1) |
| 133 | { |
| 134 | /* Find ACPI NVS to update BARs */ |
| 135 | struct global_nvs *gnvs = acpi_get_gnvs(); |
| 136 | if (!gnvs) |
| 137 | return; |
| 138 | |
| 139 | gnvs->s0b[sio_index] = bar0; |
| 140 | gnvs->s1b[sio_index] = bar1; |
| 141 | } |
| 142 | |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 143 | static void serialio_init(struct device *dev) |
| 144 | { |
Angel Pons | cbcbb67 | 2020-10-23 00:11:26 +0200 | [diff] [blame] | 145 | struct southbridge_intel_lynxpoint_config *config = config_of(dev); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 146 | struct resource *bar0, *bar1; |
| 147 | int sio_index = -1; |
| 148 | |
| 149 | printk(BIOS_DEBUG, "Initializing Serial IO device\n"); |
| 150 | |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 151 | /* Ensure memory and bus master are enabled */ |
Angel Pons | d5d4fbc | 2020-05-31 01:03:59 +0200 | [diff] [blame] | 152 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 153 | |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 154 | /* Find BAR0 and BAR1 */ |
| 155 | bar0 = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 156 | if (!bar0) |
| 157 | return; |
| 158 | bar1 = find_resource(dev, PCI_BASE_ADDRESS_1); |
| 159 | if (!bar1) |
| 160 | return; |
| 161 | |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 162 | if (!config->sio_acpi_mode) |
| 163 | serialio_enable_clock(bar0); |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 164 | |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 165 | switch (dev->path.pci.devfn) { |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 166 | case PCH_DEVFN_SDMA: /* SDMA */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 167 | sio_index = SIO_ID_SDMA; |
| 168 | serialio_init_once(config->sio_acpi_mode); |
| 169 | serialio_d21_mode(sio_index, SIO_PIN_INTB, |
| 170 | config->sio_acpi_mode); |
| 171 | break; |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 172 | case PCH_DEVFN_I2C0: /* I2C0 */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 173 | sio_index = SIO_ID_I2C0; |
| 174 | serialio_d21_ltr(bar0); |
| 175 | serialio_i2c_voltage_sel(bar0, config->sio_i2c0_voltage); |
| 176 | serialio_d21_mode(sio_index, SIO_PIN_INTC, |
| 177 | config->sio_acpi_mode); |
| 178 | break; |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 179 | case PCH_DEVFN_I2C1: /* I2C1 */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 180 | sio_index = SIO_ID_I2C1; |
| 181 | serialio_d21_ltr(bar0); |
| 182 | serialio_i2c_voltage_sel(bar0, config->sio_i2c1_voltage); |
| 183 | serialio_d21_mode(sio_index, SIO_PIN_INTC, |
| 184 | config->sio_acpi_mode); |
| 185 | break; |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 186 | case PCH_DEVFN_SPI0: /* SPI0 */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 187 | sio_index = SIO_ID_SPI0; |
| 188 | serialio_d21_ltr(bar0); |
| 189 | serialio_d21_mode(sio_index, SIO_PIN_INTC, |
| 190 | config->sio_acpi_mode); |
| 191 | break; |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 192 | case PCH_DEVFN_SPI1: /* SPI1 */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 193 | sio_index = SIO_ID_SPI1; |
| 194 | serialio_d21_ltr(bar0); |
| 195 | serialio_d21_mode(sio_index, SIO_PIN_INTC, |
| 196 | config->sio_acpi_mode); |
| 197 | break; |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 198 | case PCH_DEVFN_UART0: /* UART0 */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 199 | sio_index = SIO_ID_UART0; |
| 200 | serialio_d21_ltr(bar0); |
| 201 | serialio_d21_mode(sio_index, SIO_PIN_INTD, |
| 202 | config->sio_acpi_mode); |
| 203 | break; |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 204 | case PCH_DEVFN_UART1: /* UART1 */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 205 | sio_index = SIO_ID_UART1; |
| 206 | serialio_d21_ltr(bar0); |
| 207 | serialio_d21_mode(sio_index, SIO_PIN_INTD, |
| 208 | config->sio_acpi_mode); |
| 209 | break; |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 210 | case PCH_DEVFN_SDIO: /* SDIO */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 211 | sio_index = SIO_ID_SDIO; |
| 212 | serialio_d23_ltr(bar0); |
| 213 | serialio_d23_mode(config->sio_acpi_mode); |
| 214 | break; |
| 215 | default: |
| 216 | return; |
| 217 | } |
| 218 | |
Kyösti Mälkki | 5e82d44 | 2020-12-22 11:31:39 +0200 | [diff] [blame] | 219 | /* Save BAR0 and BAR1 to ACPI NVS */ |
| 220 | if (config->sio_acpi_mode) |
| 221 | update_bars(sio_index, (u32)bar0->base, (u32)bar1->base); |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 222 | } |
| 223 | |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 224 | static struct device_operations device_ops = { |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 225 | .read_resources = pci_dev_read_resources, |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 226 | .set_resources = pci_dev_set_resources, |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 227 | .enable_resources = pci_dev_enable_resources, |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 228 | .init = serialio_init, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 229 | .ops_pci = &pci_dev_ops_pci, |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 230 | }; |
| 231 | |
| 232 | static const unsigned short pci_device_ids[] = { |
Felix Singer | 4ea08f9 | 2020-11-20 12:56:44 +0000 | [diff] [blame] | 233 | PCI_DEVICE_ID_INTEL_LPT_LP_SDMA, |
| 234 | PCI_DEVICE_ID_INTEL_LPT_LP_I2C0, |
| 235 | PCI_DEVICE_ID_INTEL_LPT_LP_I2C1, |
| 236 | PCI_DEVICE_ID_INTEL_LPT_LP_GSPI0, |
| 237 | PCI_DEVICE_ID_INTEL_LPT_LP_GSPI1, |
| 238 | PCI_DEVICE_ID_INTEL_LPT_LP_UART0, |
| 239 | PCI_DEVICE_ID_INTEL_LPT_LP_UART1, |
| 240 | PCI_DEVICE_ID_INTEL_LPT_LP_SD, |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 241 | 0 |
| 242 | }; |
| 243 | |
| 244 | static const struct pci_driver pch_pcie __pci_driver = { |
| 245 | .ops = &device_ops, |
| 246 | .vendor = PCI_VENDOR_ID_INTEL, |
| 247 | .devices = pci_device_ids, |
| 248 | }; |