blob: 199cf9f8960b170fcf9a7aef29aec3713336f42d [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älkki12b121c2019-08-18 16:33:39 +030010#include "chip.h"
Angel Pons2178b722020-05-31 00:55:35 +020011#include "iobp.h"
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070012#include "pch.h"
13#include "nvs.h"
14
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
132static void serialio_init(struct device *dev)
133{
Angel Ponscbcbb672020-10-23 00:11:26 +0200134 struct southbridge_intel_lynxpoint_config *config = config_of(dev);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700135 struct resource *bar0, *bar1;
136 int sio_index = -1;
137
138 printk(BIOS_DEBUG, "Initializing Serial IO device\n");
139
Duncan Laurie98c40622013-05-21 16:37:40 -0700140 /* Ensure memory and bus master are enabled */
Angel Ponsd5d4fbc2020-05-31 01:03:59 +0200141 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
Duncan Laurie98c40622013-05-21 16:37:40 -0700142
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700143 /* 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 Laurie98c40622013-05-21 16:37:40 -0700151 if (!config->sio_acpi_mode)
152 serialio_enable_clock(bar0);
Duncan Laurie98c40622013-05-21 16:37:40 -0700153
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700154 switch (dev->path.pci.devfn) {
Angel Pons30392ae2020-07-12 01:06:23 +0200155 case PCH_DEVFN_SDMA: /* SDMA */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700156 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 Pons30392ae2020-07-12 01:06:23 +0200161 case PCH_DEVFN_I2C0: /* I2C0 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700162 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 Pons30392ae2020-07-12 01:06:23 +0200168 case PCH_DEVFN_I2C1: /* I2C1 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700169 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 Pons30392ae2020-07-12 01:06:23 +0200175 case PCH_DEVFN_SPI0: /* SPI0 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700176 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 Pons30392ae2020-07-12 01:06:23 +0200181 case PCH_DEVFN_SPI1: /* SPI1 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700182 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 Pons30392ae2020-07-12 01:06:23 +0200187 case PCH_DEVFN_UART0: /* UART0 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700188 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 Pons30392ae2020-07-12 01:06:23 +0200193 case PCH_DEVFN_UART1: /* UART1 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700194 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 Pons30392ae2020-07-12 01:06:23 +0200199 case PCH_DEVFN_SDIO: /* SDIO */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700200 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älkki0c1dd9c2020-06-17 23:37:49 +0300209 struct global_nvs *gnvs;
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700210
211 /* Find ACPI NVS to update BARs */
Kyösti Mälkki5daa1d32020-06-14 12:01:58 +0300212 gnvs = acpi_get_gnvs();
213 if (!gnvs)
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700214 return;
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700215
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 Laurieb39ba2e2013-03-22 11:21:14 -0700222static struct device_operations device_ops = {
Duncan Laurie98c40622013-05-21 16:37:40 -0700223 .read_resources = pci_dev_read_resources,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700224 .set_resources = pci_dev_set_resources,
Duncan Laurie98c40622013-05-21 16:37:40 -0700225 .enable_resources = pci_dev_enable_resources,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700226 .init = serialio_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200227 .ops_pci = &pci_dev_ops_pci,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700228};
229
230static 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
242static const struct pci_driver pch_pcie __pci_driver = {
243 .ops = &device_ops,
244 .vendor = PCI_VENDOR_ID_INTEL,
245 .devices = pci_device_ids,
246};