blob: 08f69fbc637f63d95db74d29404713a68a7c0400 [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"
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070011#include "pch.h"
12#include "nvs.h"
13
Duncan Laurie98c40622013-05-21 16:37:40 -070014/* Enable clock in PCI mode */
15static void serialio_enable_clock(struct resource *bar0)
16{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080017 u32 reg32 = read32(res2mmio(bar0, SIO_REG_PPR_CLOCK, 0));
Duncan Laurie98c40622013-05-21 16:37:40 -070018 reg32 |= SIO_REG_PPR_CLOCK_EN;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080019 write32(res2mmio(bar0, SIO_REG_PPR_CLOCK, 0), reg32);
Duncan Laurie98c40622013-05-21 16:37:40 -070020}
21
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070022/* Put Serial IO D21:F0-F6 device into desired mode. */
23static void serialio_d21_mode(int sio_index, int int_pin, int acpi_mode)
24{
25 u32 portctrl = SIO_IOBP_PORTCTRL_PM_CAP_PRSNT;
26
27 /* Snoop select 1. */
28 portctrl |= SIO_IOBP_PORTCTRL_SNOOP_SELECT(1);
29
30 /* Set interrupt pin. */
31 portctrl |= SIO_IOBP_PORTCTRL_INT_PIN(int_pin);
32
33 if (acpi_mode) {
34 /* Enable ACPI interrupt mode. */
35 portctrl |= SIO_IOBP_PORTCTRL_ACPI_IRQ_EN;
36
37 /* Disable PCI config space. */
38 portctrl |= SIO_IOBP_PORTCTRL_PCI_CONF_DIS;
39 }
40
41 pch_iobp_update(SIO_IOBP_PORTCTRLX(sio_index), 0, portctrl);
42}
43
44/* Put Serial IO D23:F0 device into desired mode. */
45static void serialio_d23_mode(int acpi_mode)
46{
47 u32 portctrl = 0;
48
49 /* Snoop select 1. */
50 pch_iobp_update(SIO_IOBP_PORTCTRL1, 0,
51 SIO_IOBP_PORTCTRL1_SNOOP_SELECT(1));
52
53 if (acpi_mode) {
54 /* Enable ACPI interrupt mode. */
55 portctrl |= SIO_IOBP_PORTCTRL0_ACPI_IRQ_EN;
56
57 /* Disable PCI config space. */
58 portctrl |= SIO_IOBP_PORTCTRL0_PCI_CONF_DIS;
59 }
60
61 pch_iobp_update(SIO_IOBP_PORTCTRL0, 0, portctrl);
62}
63
64/* Enable LTR Auto Mode for D21:F1-F6. */
65static void serialio_d21_ltr(struct resource *bar0)
66{
67 u32 reg;
68
69 /* 1. Program BAR0 + 808h[2] = 0b */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080070 reg = read32(res2mmio(bar0, SIO_REG_PPR_GEN, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070071 reg &= ~SIO_REG_PPR_GEN_LTR_MODE_MASK;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080072 write32(res2mmio(bar0, SIO_REG_PPR_GEN, 0), reg);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070073
74 /* 2. Program BAR0 + 804h[1:0] = 00b */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080075 reg = read32(res2mmio(bar0, SIO_REG_PPR_RST, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070076 reg &= ~SIO_REG_PPR_RST_ASSERT;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080077 write32(res2mmio(bar0, SIO_REG_PPR_RST, 0), reg);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070078
79 /* 3. Program BAR0 + 804h[1:0] = 11b */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080080 reg = read32(res2mmio(bar0, SIO_REG_PPR_RST, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070081 reg |= SIO_REG_PPR_RST_ASSERT;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080082 write32(res2mmio(bar0, SIO_REG_PPR_RST, 0), reg);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070083
84 /* 4. Program BAR0 + 814h[31:0] = 00000000h */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080085 write32(res2mmio(bar0, SIO_REG_AUTO_LTR, 0), 0);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070086}
87
88/* Enable LTR Auto Mode for D23:F0. */
89static void serialio_d23_ltr(struct resource *bar0)
90{
91 u32 reg;
92
93 /* Program BAR0 + 1008h[2] = 1b */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080094 reg = read32(res2mmio(bar0, SIO_REG_SDIO_PPR_GEN, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070095 reg |= SIO_REG_PPR_GEN_LTR_MODE_MASK;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080096 write32(res2mmio(bar0, SIO_REG_SDIO_PPR_GEN, 0), reg);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070097
98 /* Program BAR0 + 1010h = 0x00000000 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080099 write32(res2mmio(bar0, SIO_REG_SDIO_PPR_SW_LTR, 0), 0);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700100
101 /* Program BAR0 + 3Ch[30] = 1b */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800102 reg = read32(res2mmio(bar0, SIO_REG_SDIO_PPR_CMD12, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700103 reg |= SIO_REG_SDIO_PPR_CMD12_B30;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800104 write32(res2mmio(bar0, SIO_REG_SDIO_PPR_CMD12, 0), reg);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700105}
106
107/* Select I2C voltage of 1.8V or 3.3V. */
108static void serialio_i2c_voltage_sel(struct resource *bar0, u8 voltage)
109{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800110 u32 reg32 = read32(res2mmio(bar0, SIO_REG_PPR_GEN, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700111 reg32 &= ~SIO_REG_PPR_GEN_VOLTAGE_MASK;
112 reg32 |= SIO_REG_PPR_GEN_VOLTAGE(voltage);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800113 write32(res2mmio(bar0, SIO_REG_PPR_GEN, 0), reg32);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700114}
115
116/* Init sequence to be run once, done as part of D21:F0 (SDMA) init. */
117static void serialio_init_once(int acpi_mode)
118{
119 if (acpi_mode) {
120 /* Enable ACPI IRQ for IRQ13, IRQ7, IRQ6, IRQ5 in RCBA. */
121 RCBA32_OR(ACPIIRQEN, (1 << 13)|(1 << 7)|(1 << 6)|(1 << 5));
122 }
123
124 /* Program IOBP CB000154h[12,9:8,4:0] = 1001100011111b. */
125 pch_iobp_update(SIO_IOBP_GPIODF, ~0x0000131f, 0x0000131f);
126
127 /* Program IOBP CB000180h[5:0] = 111111b (undefined register) */
128 pch_iobp_update(0xcb000180, ~0x0000003f, 0x0000003f);
129}
130
131static void serialio_init(struct device *dev)
132{
133 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
134 struct resource *bar0, *bar1;
135 int sio_index = -1;
136
137 printk(BIOS_DEBUG, "Initializing Serial IO device\n");
138
Duncan Laurie98c40622013-05-21 16:37:40 -0700139 /* Ensure memory and bus master are enabled */
Angel Ponsd5d4fbc2020-05-31 01:03:59 +0200140 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
Duncan Laurie98c40622013-05-21 16:37:40 -0700141
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700142 /* Find BAR0 and BAR1 */
143 bar0 = find_resource(dev, PCI_BASE_ADDRESS_0);
144 if (!bar0)
145 return;
146 bar1 = find_resource(dev, PCI_BASE_ADDRESS_1);
147 if (!bar1)
148 return;
149
Duncan Laurie98c40622013-05-21 16:37:40 -0700150 if (!config->sio_acpi_mode)
151 serialio_enable_clock(bar0);
Duncan Laurie98c40622013-05-21 16:37:40 -0700152
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700153 switch (dev->path.pci.devfn) {
Angel Pons30392ae2020-07-12 01:06:23 +0200154 case PCH_DEVFN_SDMA: /* SDMA */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700155 sio_index = SIO_ID_SDMA;
156 serialio_init_once(config->sio_acpi_mode);
157 serialio_d21_mode(sio_index, SIO_PIN_INTB,
158 config->sio_acpi_mode);
159 break;
Angel Pons30392ae2020-07-12 01:06:23 +0200160 case PCH_DEVFN_I2C0: /* I2C0 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700161 sio_index = SIO_ID_I2C0;
162 serialio_d21_ltr(bar0);
163 serialio_i2c_voltage_sel(bar0, config->sio_i2c0_voltage);
164 serialio_d21_mode(sio_index, SIO_PIN_INTC,
165 config->sio_acpi_mode);
166 break;
Angel Pons30392ae2020-07-12 01:06:23 +0200167 case PCH_DEVFN_I2C1: /* I2C1 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700168 sio_index = SIO_ID_I2C1;
169 serialio_d21_ltr(bar0);
170 serialio_i2c_voltage_sel(bar0, config->sio_i2c1_voltage);
171 serialio_d21_mode(sio_index, SIO_PIN_INTC,
172 config->sio_acpi_mode);
173 break;
Angel Pons30392ae2020-07-12 01:06:23 +0200174 case PCH_DEVFN_SPI0: /* SPI0 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700175 sio_index = SIO_ID_SPI0;
176 serialio_d21_ltr(bar0);
177 serialio_d21_mode(sio_index, SIO_PIN_INTC,
178 config->sio_acpi_mode);
179 break;
Angel Pons30392ae2020-07-12 01:06:23 +0200180 case PCH_DEVFN_SPI1: /* SPI1 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700181 sio_index = SIO_ID_SPI1;
182 serialio_d21_ltr(bar0);
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_UART0: /* UART0 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700187 sio_index = SIO_ID_UART0;
188 serialio_d21_ltr(bar0);
189 serialio_d21_mode(sio_index, SIO_PIN_INTD,
190 config->sio_acpi_mode);
191 break;
Angel Pons30392ae2020-07-12 01:06:23 +0200192 case PCH_DEVFN_UART1: /* UART1 */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700193 sio_index = SIO_ID_UART1;
194 serialio_d21_ltr(bar0);
195 serialio_d21_mode(sio_index, SIO_PIN_INTD,
196 config->sio_acpi_mode);
197 break;
Angel Pons30392ae2020-07-12 01:06:23 +0200198 case PCH_DEVFN_SDIO: /* SDIO */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700199 sio_index = SIO_ID_SDIO;
200 serialio_d23_ltr(bar0);
201 serialio_d23_mode(config->sio_acpi_mode);
202 break;
203 default:
204 return;
205 }
206
207 if (config->sio_acpi_mode) {
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300208 struct global_nvs *gnvs;
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700209
210 /* Find ACPI NVS to update BARs */
Kyösti Mälkki5daa1d32020-06-14 12:01:58 +0300211 gnvs = acpi_get_gnvs();
212 if (!gnvs)
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700213 return;
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700214
215 /* Save BAR0 and BAR1 to ACPI NVS */
216 gnvs->s0b[sio_index] = (u32)bar0->base;
217 gnvs->s1b[sio_index] = (u32)bar1->base;
218 }
219}
220
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700221static struct device_operations device_ops = {
Duncan Laurie98c40622013-05-21 16:37:40 -0700222 .read_resources = pci_dev_read_resources,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700223 .set_resources = pci_dev_set_resources,
Duncan Laurie98c40622013-05-21 16:37:40 -0700224 .enable_resources = pci_dev_enable_resources,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700225 .init = serialio_init,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200226 .ops_pci = &pci_dev_ops_pci,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700227};
228
229static const unsigned short pci_device_ids[] = {
230 0x9c60, /* 0:15.0 - SDMA */
231 0x9c61, /* 0:15.1 - I2C0 */
232 0x9c62, /* 0:15.2 - I2C1 */
233 0x9c65, /* 0:15.3 - SPI0 */
234 0x9c66, /* 0:15.4 - SPI1 */
235 0x9c63, /* 0:15.5 - UART0 */
236 0x9c64, /* 0:15.6 - UART1 */
237 0x9c35, /* 0:17.0 - SDIO */
238 0
239};
240
241static const struct pci_driver pch_pcie __pci_driver = {
242 .ops = &device_ops,
243 .vendor = PCI_VENDOR_ID_INTEL,
244 .devices = pci_device_ids,
245};