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 | 12b121c | 2019-08-18 16:33:39 +0300 | [diff] [blame] | 10 | #include "chip.h" |
Angel Pons | 2178b72 | 2020-05-31 00:55:35 +0200 | [diff] [blame] | 11 | #include "iobp.h" |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 12 | #include "pch.h" |
| 13 | #include "nvs.h" |
| 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 | |
| 132 | static void serialio_init(struct device *dev) |
| 133 | { |
| 134 | struct southbridge_intel_lynxpoint_config *config = dev->chip_info; |
| 135 | struct resource *bar0, *bar1; |
| 136 | int sio_index = -1; |
| 137 | |
| 138 | printk(BIOS_DEBUG, "Initializing Serial IO device\n"); |
| 139 | |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 140 | /* Ensure memory and bus master are enabled */ |
Angel Pons | d5d4fbc | 2020-05-31 01:03:59 +0200 | [diff] [blame] | 141 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY); |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 142 | |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 143 | /* Find BAR0 and BAR1 */ |
| 144 | bar0 = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 145 | if (!bar0) |
| 146 | return; |
| 147 | bar1 = find_resource(dev, PCI_BASE_ADDRESS_1); |
| 148 | if (!bar1) |
| 149 | return; |
| 150 | |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 151 | if (!config->sio_acpi_mode) |
| 152 | serialio_enable_clock(bar0); |
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 | switch (dev->path.pci.devfn) { |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 155 | case PCH_DEVFN_SDMA: /* SDMA */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 156 | sio_index = SIO_ID_SDMA; |
| 157 | serialio_init_once(config->sio_acpi_mode); |
| 158 | serialio_d21_mode(sio_index, SIO_PIN_INTB, |
| 159 | config->sio_acpi_mode); |
| 160 | break; |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 161 | case PCH_DEVFN_I2C0: /* I2C0 */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 162 | sio_index = SIO_ID_I2C0; |
| 163 | serialio_d21_ltr(bar0); |
| 164 | serialio_i2c_voltage_sel(bar0, config->sio_i2c0_voltage); |
| 165 | serialio_d21_mode(sio_index, SIO_PIN_INTC, |
| 166 | config->sio_acpi_mode); |
| 167 | break; |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 168 | case PCH_DEVFN_I2C1: /* I2C1 */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 169 | sio_index = SIO_ID_I2C1; |
| 170 | serialio_d21_ltr(bar0); |
| 171 | serialio_i2c_voltage_sel(bar0, config->sio_i2c1_voltage); |
| 172 | serialio_d21_mode(sio_index, SIO_PIN_INTC, |
| 173 | config->sio_acpi_mode); |
| 174 | break; |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 175 | case PCH_DEVFN_SPI0: /* SPI0 */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 176 | sio_index = SIO_ID_SPI0; |
| 177 | serialio_d21_ltr(bar0); |
| 178 | serialio_d21_mode(sio_index, SIO_PIN_INTC, |
| 179 | config->sio_acpi_mode); |
| 180 | break; |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 181 | case PCH_DEVFN_SPI1: /* SPI1 */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 182 | sio_index = SIO_ID_SPI1; |
| 183 | serialio_d21_ltr(bar0); |
| 184 | serialio_d21_mode(sio_index, SIO_PIN_INTC, |
| 185 | config->sio_acpi_mode); |
| 186 | break; |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 187 | case PCH_DEVFN_UART0: /* UART0 */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 188 | sio_index = SIO_ID_UART0; |
| 189 | serialio_d21_ltr(bar0); |
| 190 | serialio_d21_mode(sio_index, SIO_PIN_INTD, |
| 191 | config->sio_acpi_mode); |
| 192 | break; |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 193 | case PCH_DEVFN_UART1: /* UART1 */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 194 | sio_index = SIO_ID_UART1; |
| 195 | serialio_d21_ltr(bar0); |
| 196 | serialio_d21_mode(sio_index, SIO_PIN_INTD, |
| 197 | config->sio_acpi_mode); |
| 198 | break; |
Angel Pons | 30392ae | 2020-07-12 01:06:23 +0200 | [diff] [blame] | 199 | case PCH_DEVFN_SDIO: /* SDIO */ |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 200 | sio_index = SIO_ID_SDIO; |
| 201 | serialio_d23_ltr(bar0); |
| 202 | serialio_d23_mode(config->sio_acpi_mode); |
| 203 | break; |
| 204 | default: |
| 205 | return; |
| 206 | } |
| 207 | |
| 208 | if (config->sio_acpi_mode) { |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 209 | struct global_nvs *gnvs; |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 210 | |
| 211 | /* Find ACPI NVS to update BARs */ |
Kyösti Mälkki | 5daa1d3 | 2020-06-14 12:01:58 +0300 | [diff] [blame] | 212 | gnvs = acpi_get_gnvs(); |
| 213 | if (!gnvs) |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 214 | return; |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 215 | |
| 216 | /* Save BAR0 and BAR1 to ACPI NVS */ |
| 217 | gnvs->s0b[sio_index] = (u32)bar0->base; |
| 218 | gnvs->s1b[sio_index] = (u32)bar1->base; |
| 219 | } |
| 220 | } |
| 221 | |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 222 | static struct device_operations device_ops = { |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 223 | .read_resources = pci_dev_read_resources, |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 224 | .set_resources = pci_dev_set_resources, |
Duncan Laurie | 98c4062 | 2013-05-21 16:37:40 -0700 | [diff] [blame] | 225 | .enable_resources = pci_dev_enable_resources, |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 226 | .init = serialio_init, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 227 | .ops_pci = &pci_dev_ops_pci, |
Duncan Laurie | b39ba2e | 2013-03-22 11:21:14 -0700 | [diff] [blame] | 228 | }; |
| 229 | |
| 230 | static const unsigned short pci_device_ids[] = { |
| 231 | 0x9c60, /* 0:15.0 - SDMA */ |
| 232 | 0x9c61, /* 0:15.1 - I2C0 */ |
| 233 | 0x9c62, /* 0:15.2 - I2C1 */ |
| 234 | 0x9c65, /* 0:15.3 - SPI0 */ |
| 235 | 0x9c66, /* 0:15.4 - SPI1 */ |
| 236 | 0x9c63, /* 0:15.5 - UART0 */ |
| 237 | 0x9c64, /* 0:15.6 - UART1 */ |
| 238 | 0x9c35, /* 0:17.0 - SDIO */ |
| 239 | 0 |
| 240 | }; |
| 241 | |
| 242 | static const struct pci_driver pch_pcie __pci_driver = { |
| 243 | .ops = &device_ops, |
| 244 | .vendor = PCI_VENDOR_ID_INTEL, |
| 245 | .devices = pci_device_ids, |
| 246 | }; |