blob: 05263fec39dd4ef4f4b1a4f34b32f0ac84b4b9b6 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -07002
Kyösti Mälkki13f66502019-03-03 08:01:05 +02003#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02004#include <device/pci_ops.h>
Kyösti Mälkki5daa1d32020-06-14 12:01:58 +03005#include <acpi/acpi_gnvs.h>
Duncan Laurieb39ba2e2013-03-22 11:21:14 -07006#include <console/console.h>
7#include <device/device.h>
8#include <device/pci.h>
Duncan Laurieb39ba2e2013-03-22 11:21:14 -07009#include <device/pci_ids.h>
Kyösti Mälkki661ad462020-12-29 06:26:21 +020010#include <soc/nvs.h>
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030011#include "chip.h"
Angel Pons2178b722020-05-31 00:55:35 +020012#include "iobp.h"
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070013#include "pch.h"
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070014
Duncan Laurie98c40622013-05-21 16:37:40 -070015/* Enable clock in PCI mode */
16static void serialio_enable_clock(struct resource *bar0)
17{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080018 u32 reg32 = read32(res2mmio(bar0, SIO_REG_PPR_CLOCK, 0));
Duncan Laurie98c40622013-05-21 16:37:40 -070019 reg32 |= SIO_REG_PPR_CLOCK_EN;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080020 write32(res2mmio(bar0, SIO_REG_PPR_CLOCK, 0), reg32);
Duncan Laurie98c40622013-05-21 16:37:40 -070021}
22
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070023/* Put Serial IO D21:F0-F6 device into desired mode. */
24static 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. */
46static 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. */
66static void serialio_d21_ltr(struct resource *bar0)
67{
68 u32 reg;
69
70 /* 1. Program BAR0 + 808h[2] = 0b */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080071 reg = read32(res2mmio(bar0, SIO_REG_PPR_GEN, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070072 reg &= ~SIO_REG_PPR_GEN_LTR_MODE_MASK;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080073 write32(res2mmio(bar0, SIO_REG_PPR_GEN, 0), reg);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070074
75 /* 2. Program BAR0 + 804h[1:0] = 00b */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080076 reg = read32(res2mmio(bar0, SIO_REG_PPR_RST, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070077 reg &= ~SIO_REG_PPR_RST_ASSERT;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080078 write32(res2mmio(bar0, SIO_REG_PPR_RST, 0), reg);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070079
80 /* 3. Program BAR0 + 804h[1:0] = 11b */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080081 reg = read32(res2mmio(bar0, SIO_REG_PPR_RST, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070082 reg |= SIO_REG_PPR_RST_ASSERT;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080083 write32(res2mmio(bar0, SIO_REG_PPR_RST, 0), reg);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070084
85 /* 4. Program BAR0 + 814h[31:0] = 00000000h */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080086 write32(res2mmio(bar0, SIO_REG_AUTO_LTR, 0), 0);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070087}
88
89/* Enable LTR Auto Mode for D23:F0. */
90static void serialio_d23_ltr(struct resource *bar0)
91{
92 u32 reg;
93
94 /* Program BAR0 + 1008h[2] = 1b */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080095 reg = read32(res2mmio(bar0, SIO_REG_SDIO_PPR_GEN, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070096 reg |= SIO_REG_PPR_GEN_LTR_MODE_MASK;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080097 write32(res2mmio(bar0, SIO_REG_SDIO_PPR_GEN, 0), reg);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070098
99 /* Program BAR0 + 1010h = 0x00000000 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800100 write32(res2mmio(bar0, SIO_REG_SDIO_PPR_SW_LTR, 0), 0);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700101
102 /* Program BAR0 + 3Ch[30] = 1b */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800103 reg = read32(res2mmio(bar0, SIO_REG_SDIO_PPR_CMD12, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700104 reg |= SIO_REG_SDIO_PPR_CMD12_B30;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800105 write32(res2mmio(bar0, SIO_REG_SDIO_PPR_CMD12, 0), reg);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700106}
107
108/* Select I2C voltage of 1.8V or 3.3V. */
109static void serialio_i2c_voltage_sel(struct resource *bar0, u8 voltage)
110{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800111 u32 reg32 = read32(res2mmio(bar0, SIO_REG_PPR_GEN, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700112 reg32 &= ~SIO_REG_PPR_GEN_VOLTAGE_MASK;
113 reg32 |= SIO_REG_PPR_GEN_VOLTAGE(voltage);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800114 write32(res2mmio(bar0, SIO_REG_PPR_GEN, 0), reg32);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700115}
116
117/* Init sequence to be run once, done as part of D21:F0 (SDMA) init. */
118static void serialio_init_once(int acpi_mode)
119{
120 if (acpi_mode) {
121 /* Enable ACPI IRQ for IRQ13, IRQ7, IRQ6, IRQ5 in RCBA. */
Angel Pons84fa2242020-10-24 11:53:47 +0200122 RCBA32_OR(ACPIIRQEN, (1 << 13) | (1 << 7) | (1 << 6) | (1 << 5));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700123 }
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älkki5e82d442020-12-22 11:31:39 +0200132static 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 Laurieb39ba2e2013-03-22 11:21:14 -0700143static void serialio_init(struct device *dev)
144{
Angel Ponscbcbb672020-10-23 00:11:26 +0200145 struct southbridge_intel_lynxpoint_config *config = config_of(dev);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700146 struct resource *bar0, *bar1;
147 int sio_index = -1;
148
149 printk(BIOS_DEBUG, "Initializing Serial IO device\n");
150
Duncan Laurie98c40622013-05-21 16:37:40 -0700151 /* Ensure memory and bus master are enabled */
Angel Ponsd5d4fbc2020-05-31 01:03:59 +0200152 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
Duncan Laurie98c40622013-05-21 16:37:40 -0700153
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700154 /* 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 Laurie98c40622013-05-21 16:37:40 -0700162 if (!config->sio_acpi_mode)
163 serialio_enable_clock(bar0);
Duncan Laurie98c40622013-05-21 16:37:40 -0700164
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700165 switch (dev->path.pci.devfn) {
Angel Pons30392ae2020-07-12 01:06:23 +0200166 case PCH_DEVFN_SDMA: /* SDMA */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700167 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 Pons30392ae2020-07-12 01:06:23 +0200172 case PCH_DEVFN_I2C0: /* I2C0 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700173 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 Pons30392ae2020-07-12 01:06:23 +0200179 case PCH_DEVFN_I2C1: /* I2C1 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700180 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 Pons30392ae2020-07-12 01:06:23 +0200186 case PCH_DEVFN_SPI0: /* SPI0 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700187 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 Pons30392ae2020-07-12 01:06:23 +0200192 case PCH_DEVFN_SPI1: /* SPI1 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700193 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 Pons30392ae2020-07-12 01:06:23 +0200198 case PCH_DEVFN_UART0: /* UART0 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700199 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 Pons30392ae2020-07-12 01:06:23 +0200204 case PCH_DEVFN_UART1: /* UART1 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700205 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 Pons30392ae2020-07-12 01:06:23 +0200210 case PCH_DEVFN_SDIO: /* SDIO */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700211 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älkki5e82d442020-12-22 11:31:39 +0200219 /* 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 Laurieb39ba2e2013-03-22 11:21:14 -0700222}
223
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700224static struct device_operations device_ops = {
Duncan Laurie98c40622013-05-21 16:37:40 -0700225 .read_resources = pci_dev_read_resources,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700226 .set_resources = pci_dev_set_resources,
Duncan Laurie98c40622013-05-21 16:37:40 -0700227 .enable_resources = pci_dev_enable_resources,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700228 .init = serialio_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200229 .ops_pci = &pci_dev_ops_pci,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700230};
231
232static const unsigned short pci_device_ids[] = {
Felix Singer4ea08f92020-11-20 12:56:44 +0000233 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 Laurieb39ba2e2013-03-22 11:21:14 -0700241 0
242};
243
244static const struct pci_driver pch_pcie __pci_driver = {
245 .ops = &device_ops,
246 .vendor = PCI_VENDOR_ID_INTEL,
247 .devices = pci_device_ids,
248};