blob: 4591566e1b2c1cb9d23d67af4fc776e2b0831361 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Duncan Laurieb39ba2e2013-03-22 11:21:14 -07003
Kyösti Mälkki13f66502019-03-03 08:01:05 +02004#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Duncan Laurieb39ba2e2013-03-22 11:21:14 -07006#include <cbmem.h>
7#include <console/console.h>
8#include <device/device.h>
9#include <device/pci.h>
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070010#include <device/pci_ids.h>
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030011#include "chip.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. */
122 RCBA32_OR(ACPIIRQEN, (1 << 13)|(1 << 7)|(1 << 6)|(1 << 5));
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
132static 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;
Duncan Laurie98c40622013-05-21 16:37:40 -0700137 u32 reg32;
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700138
139 printk(BIOS_DEBUG, "Initializing Serial IO device\n");
140
Duncan Laurie98c40622013-05-21 16:37:40 -0700141 /* Ensure memory and bus master are enabled */
142 reg32 = pci_read_config32(dev, PCI_COMMAND);
143 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
144 pci_write_config32(dev, PCI_COMMAND, reg32);
145
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700146 /* Find BAR0 and BAR1 */
147 bar0 = find_resource(dev, PCI_BASE_ADDRESS_0);
148 if (!bar0)
149 return;
150 bar1 = find_resource(dev, PCI_BASE_ADDRESS_1);
151 if (!bar1)
152 return;
153
Duncan Laurie98c40622013-05-21 16:37:40 -0700154 if (!config->sio_acpi_mode)
155 serialio_enable_clock(bar0);
Duncan Laurie98c40622013-05-21 16:37:40 -0700156
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700157 switch (dev->path.pci.devfn) {
158 case PCI_DEVFN(21, 0): /* SDMA */
159 sio_index = SIO_ID_SDMA;
160 serialio_init_once(config->sio_acpi_mode);
161 serialio_d21_mode(sio_index, SIO_PIN_INTB,
162 config->sio_acpi_mode);
163 break;
164 case PCI_DEVFN(21, 1): /* I2C0 */
165 sio_index = SIO_ID_I2C0;
166 serialio_d21_ltr(bar0);
167 serialio_i2c_voltage_sel(bar0, config->sio_i2c0_voltage);
168 serialio_d21_mode(sio_index, SIO_PIN_INTC,
169 config->sio_acpi_mode);
170 break;
171 case PCI_DEVFN(21, 2): /* I2C1 */
172 sio_index = SIO_ID_I2C1;
173 serialio_d21_ltr(bar0);
174 serialio_i2c_voltage_sel(bar0, config->sio_i2c1_voltage);
175 serialio_d21_mode(sio_index, SIO_PIN_INTC,
176 config->sio_acpi_mode);
177 break;
178 case PCI_DEVFN(21, 3): /* SPI0 */
179 sio_index = SIO_ID_SPI0;
180 serialio_d21_ltr(bar0);
181 serialio_d21_mode(sio_index, SIO_PIN_INTC,
182 config->sio_acpi_mode);
183 break;
184 case PCI_DEVFN(21, 4): /* SPI1 */
185 sio_index = SIO_ID_SPI1;
186 serialio_d21_ltr(bar0);
187 serialio_d21_mode(sio_index, SIO_PIN_INTC,
188 config->sio_acpi_mode);
189 break;
190 case PCI_DEVFN(21, 5): /* UART0 */
191 sio_index = SIO_ID_UART0;
192 serialio_d21_ltr(bar0);
193 serialio_d21_mode(sio_index, SIO_PIN_INTD,
194 config->sio_acpi_mode);
195 break;
196 case PCI_DEVFN(21, 6): /* UART1 */
197 sio_index = SIO_ID_UART1;
198 serialio_d21_ltr(bar0);
199 serialio_d21_mode(sio_index, SIO_PIN_INTD,
200 config->sio_acpi_mode);
201 break;
202 case PCI_DEVFN(23, 0): /* SDIO */
203 sio_index = SIO_ID_SDIO;
204 serialio_d23_ltr(bar0);
205 serialio_d23_mode(config->sio_acpi_mode);
206 break;
207 default:
208 return;
209 }
210
211 if (config->sio_acpi_mode) {
212 global_nvs_t *gnvs;
213
214 /* Find ACPI NVS to update BARs */
215 gnvs = (global_nvs_t *)cbmem_find(CBMEM_ID_ACPI_GNVS);
216 if (!gnvs) {
217 printk(BIOS_ERR, "Unable to locate Global NVS\n");
218 return;
219 }
220
221 /* Save BAR0 and BAR1 to ACPI NVS */
222 gnvs->s0b[sio_index] = (u32)bar0->base;
223 gnvs->s1b[sio_index] = (u32)bar1->base;
224 }
225}
226
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700227static struct pci_operations pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530228 .set_subsystem = pci_dev_set_subsystem,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700229};
230
231static struct device_operations device_ops = {
Duncan Laurie98c40622013-05-21 16:37:40 -0700232 .read_resources = pci_dev_read_resources,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700233 .set_resources = pci_dev_set_resources,
Duncan Laurie98c40622013-05-21 16:37:40 -0700234 .enable_resources = pci_dev_enable_resources,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700235 .init = serialio_init,
236 .ops_pci = &pci_ops,
237};
238
239static const unsigned short pci_device_ids[] = {
240 0x9c60, /* 0:15.0 - SDMA */
241 0x9c61, /* 0:15.1 - I2C0 */
242 0x9c62, /* 0:15.2 - I2C1 */
243 0x9c65, /* 0:15.3 - SPI0 */
244 0x9c66, /* 0:15.4 - SPI1 */
245 0x9c63, /* 0:15.5 - UART0 */
246 0x9c64, /* 0:15.6 - UART1 */
247 0x9c35, /* 0:17.0 - SDIO */
248 0
249};
250
251static const struct pci_driver pch_pcie __pci_driver = {
252 .ops = &device_ops,
253 .vendor = PCI_VENDOR_ID_INTEL,
254 .devices = pci_device_ids,
255};