blob: adb9067dbca887fd9dde55280ddc7d5e5f23a226 [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>
Duncan Laurieb39ba2e2013-03-22 11:21:14 -07005#include <cbmem.h>
6#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) {
154 case PCI_DEVFN(21, 0): /* SDMA */
155 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;
160 case PCI_DEVFN(21, 1): /* I2C0 */
161 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;
167 case PCI_DEVFN(21, 2): /* I2C1 */
168 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;
174 case PCI_DEVFN(21, 3): /* SPI0 */
175 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;
180 case PCI_DEVFN(21, 4): /* SPI1 */
181 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;
186 case PCI_DEVFN(21, 5): /* UART0 */
187 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;
192 case PCI_DEVFN(21, 6): /* UART1 */
193 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;
198 case PCI_DEVFN(23, 0): /* SDIO */
199 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) {
208 global_nvs_t *gnvs;
209
210 /* Find ACPI NVS to update BARs */
211 gnvs = (global_nvs_t *)cbmem_find(CBMEM_ID_ACPI_GNVS);
212 if (!gnvs) {
213 printk(BIOS_ERR, "Unable to locate Global NVS\n");
214 return;
215 }
216
217 /* Save BAR0 and BAR1 to ACPI NVS */
218 gnvs->s0b[sio_index] = (u32)bar0->base;
219 gnvs->s1b[sio_index] = (u32)bar1->base;
220 }
221}
222
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700223static struct pci_operations pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530224 .set_subsystem = pci_dev_set_subsystem,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700225};
226
227static struct device_operations device_ops = {
Duncan Laurie98c40622013-05-21 16:37:40 -0700228 .read_resources = pci_dev_read_resources,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700229 .set_resources = pci_dev_set_resources,
Duncan Laurie98c40622013-05-21 16:37:40 -0700230 .enable_resources = pci_dev_enable_resources,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700231 .init = serialio_init,
232 .ops_pci = &pci_ops,
233};
234
235static const unsigned short pci_device_ids[] = {
236 0x9c60, /* 0:15.0 - SDMA */
237 0x9c61, /* 0:15.1 - I2C0 */
238 0x9c62, /* 0:15.2 - I2C1 */
239 0x9c65, /* 0:15.3 - SPI0 */
240 0x9c66, /* 0:15.4 - SPI1 */
241 0x9c63, /* 0:15.5 - UART0 */
242 0x9c64, /* 0:15.6 - UART1 */
243 0x9c35, /* 0:17.0 - SDIO */
244 0
245};
246
247static const struct pci_driver pch_pcie __pci_driver = {
248 .ops = &device_ops,
249 .vendor = PCI_VENDOR_ID_INTEL,
250 .devices = pci_device_ids,
251};