blob: da2a47a0334bf53c448053e79c9703cb78a7e71c [file] [log] [blame]
Duncan Laurieb39ba2e2013-03-22 11:21:14 -07001/*
2 * This file is part of the coreboot project.
3 *
Duncan Laurieb39ba2e2013-03-22 11:21:14 -07004 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; version 2 of
8 * the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070014 */
15
Kyösti Mälkki13f66502019-03-03 08:01:05 +020016#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020017#include <device/pci_ops.h>
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070018#include <cbmem.h>
19#include <console/console.h>
20#include <device/device.h>
21#include <device/pci.h>
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070022#include <device/pci_ids.h>
Kyösti Mälkki12b121c2019-08-18 16:33:39 +030023#include "chip.h"
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070024#include "pch.h"
25#include "nvs.h"
26
Duncan Laurie98c40622013-05-21 16:37:40 -070027/* Enable clock in PCI mode */
28static void serialio_enable_clock(struct resource *bar0)
29{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080030 u32 reg32 = read32(res2mmio(bar0, SIO_REG_PPR_CLOCK, 0));
Duncan Laurie98c40622013-05-21 16:37:40 -070031 reg32 |= SIO_REG_PPR_CLOCK_EN;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080032 write32(res2mmio(bar0, SIO_REG_PPR_CLOCK, 0), reg32);
Duncan Laurie98c40622013-05-21 16:37:40 -070033}
34
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070035/* Put Serial IO D21:F0-F6 device into desired mode. */
36static void serialio_d21_mode(int sio_index, int int_pin, int acpi_mode)
37{
38 u32 portctrl = SIO_IOBP_PORTCTRL_PM_CAP_PRSNT;
39
40 /* Snoop select 1. */
41 portctrl |= SIO_IOBP_PORTCTRL_SNOOP_SELECT(1);
42
43 /* Set interrupt pin. */
44 portctrl |= SIO_IOBP_PORTCTRL_INT_PIN(int_pin);
45
46 if (acpi_mode) {
47 /* Enable ACPI interrupt mode. */
48 portctrl |= SIO_IOBP_PORTCTRL_ACPI_IRQ_EN;
49
50 /* Disable PCI config space. */
51 portctrl |= SIO_IOBP_PORTCTRL_PCI_CONF_DIS;
52 }
53
54 pch_iobp_update(SIO_IOBP_PORTCTRLX(sio_index), 0, portctrl);
55}
56
57/* Put Serial IO D23:F0 device into desired mode. */
58static void serialio_d23_mode(int acpi_mode)
59{
60 u32 portctrl = 0;
61
62 /* Snoop select 1. */
63 pch_iobp_update(SIO_IOBP_PORTCTRL1, 0,
64 SIO_IOBP_PORTCTRL1_SNOOP_SELECT(1));
65
66 if (acpi_mode) {
67 /* Enable ACPI interrupt mode. */
68 portctrl |= SIO_IOBP_PORTCTRL0_ACPI_IRQ_EN;
69
70 /* Disable PCI config space. */
71 portctrl |= SIO_IOBP_PORTCTRL0_PCI_CONF_DIS;
72 }
73
74 pch_iobp_update(SIO_IOBP_PORTCTRL0, 0, portctrl);
75}
76
77/* Enable LTR Auto Mode for D21:F1-F6. */
78static void serialio_d21_ltr(struct resource *bar0)
79{
80 u32 reg;
81
82 /* 1. Program BAR0 + 808h[2] = 0b */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080083 reg = read32(res2mmio(bar0, SIO_REG_PPR_GEN, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070084 reg &= ~SIO_REG_PPR_GEN_LTR_MODE_MASK;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080085 write32(res2mmio(bar0, SIO_REG_PPR_GEN, 0), reg);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070086
87 /* 2. Program BAR0 + 804h[1:0] = 00b */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080088 reg = read32(res2mmio(bar0, SIO_REG_PPR_RST, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070089 reg &= ~SIO_REG_PPR_RST_ASSERT;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080090 write32(res2mmio(bar0, SIO_REG_PPR_RST, 0), reg);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070091
92 /* 3. Program BAR0 + 804h[1:0] = 11b */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080093 reg = read32(res2mmio(bar0, SIO_REG_PPR_RST, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070094 reg |= SIO_REG_PPR_RST_ASSERT;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080095 write32(res2mmio(bar0, SIO_REG_PPR_RST, 0), reg);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070096
97 /* 4. Program BAR0 + 814h[31:0] = 00000000h */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080098 write32(res2mmio(bar0, SIO_REG_AUTO_LTR, 0), 0);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -070099}
100
101/* Enable LTR Auto Mode for D23:F0. */
102static void serialio_d23_ltr(struct resource *bar0)
103{
104 u32 reg;
105
106 /* Program BAR0 + 1008h[2] = 1b */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800107 reg = read32(res2mmio(bar0, SIO_REG_SDIO_PPR_GEN, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700108 reg |= SIO_REG_PPR_GEN_LTR_MODE_MASK;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800109 write32(res2mmio(bar0, SIO_REG_SDIO_PPR_GEN, 0), reg);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700110
111 /* Program BAR0 + 1010h = 0x00000000 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800112 write32(res2mmio(bar0, SIO_REG_SDIO_PPR_SW_LTR, 0), 0);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700113
114 /* Program BAR0 + 3Ch[30] = 1b */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800115 reg = read32(res2mmio(bar0, SIO_REG_SDIO_PPR_CMD12, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700116 reg |= SIO_REG_SDIO_PPR_CMD12_B30;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800117 write32(res2mmio(bar0, SIO_REG_SDIO_PPR_CMD12, 0), reg);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700118}
119
120/* Select I2C voltage of 1.8V or 3.3V. */
121static void serialio_i2c_voltage_sel(struct resource *bar0, u8 voltage)
122{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800123 u32 reg32 = read32(res2mmio(bar0, SIO_REG_PPR_GEN, 0));
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700124 reg32 &= ~SIO_REG_PPR_GEN_VOLTAGE_MASK;
125 reg32 |= SIO_REG_PPR_GEN_VOLTAGE(voltage);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800126 write32(res2mmio(bar0, SIO_REG_PPR_GEN, 0), reg32);
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700127}
128
129/* Init sequence to be run once, done as part of D21:F0 (SDMA) init. */
130static void serialio_init_once(int acpi_mode)
131{
132 if (acpi_mode) {
133 /* Enable ACPI IRQ for IRQ13, IRQ7, IRQ6, IRQ5 in RCBA. */
134 RCBA32_OR(ACPIIRQEN, (1 << 13)|(1 << 7)|(1 << 6)|(1 << 5));
135 }
136
137 /* Program IOBP CB000154h[12,9:8,4:0] = 1001100011111b. */
138 pch_iobp_update(SIO_IOBP_GPIODF, ~0x0000131f, 0x0000131f);
139
140 /* Program IOBP CB000180h[5:0] = 111111b (undefined register) */
141 pch_iobp_update(0xcb000180, ~0x0000003f, 0x0000003f);
142}
143
144static void serialio_init(struct device *dev)
145{
146 struct southbridge_intel_lynxpoint_config *config = dev->chip_info;
147 struct resource *bar0, *bar1;
148 int sio_index = -1;
Duncan Laurie98c40622013-05-21 16:37:40 -0700149 u32 reg32;
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700150
151 printk(BIOS_DEBUG, "Initializing Serial IO device\n");
152
Duncan Laurie98c40622013-05-21 16:37:40 -0700153 /* Ensure memory and bus master are enabled */
154 reg32 = pci_read_config32(dev, PCI_COMMAND);
155 reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
156 pci_write_config32(dev, PCI_COMMAND, reg32);
157
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700158 /* Find BAR0 and BAR1 */
159 bar0 = find_resource(dev, PCI_BASE_ADDRESS_0);
160 if (!bar0)
161 return;
162 bar1 = find_resource(dev, PCI_BASE_ADDRESS_1);
163 if (!bar1)
164 return;
165
Duncan Laurie98c40622013-05-21 16:37:40 -0700166 if (!config->sio_acpi_mode)
167 serialio_enable_clock(bar0);
Duncan Laurie98c40622013-05-21 16:37:40 -0700168
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700169 switch (dev->path.pci.devfn) {
170 case PCI_DEVFN(21, 0): /* SDMA */
171 sio_index = SIO_ID_SDMA;
172 serialio_init_once(config->sio_acpi_mode);
173 serialio_d21_mode(sio_index, SIO_PIN_INTB,
174 config->sio_acpi_mode);
175 break;
176 case PCI_DEVFN(21, 1): /* I2C0 */
177 sio_index = SIO_ID_I2C0;
178 serialio_d21_ltr(bar0);
179 serialio_i2c_voltage_sel(bar0, config->sio_i2c0_voltage);
180 serialio_d21_mode(sio_index, SIO_PIN_INTC,
181 config->sio_acpi_mode);
182 break;
183 case PCI_DEVFN(21, 2): /* I2C1 */
184 sio_index = SIO_ID_I2C1;
185 serialio_d21_ltr(bar0);
186 serialio_i2c_voltage_sel(bar0, config->sio_i2c1_voltage);
187 serialio_d21_mode(sio_index, SIO_PIN_INTC,
188 config->sio_acpi_mode);
189 break;
190 case PCI_DEVFN(21, 3): /* SPI0 */
191 sio_index = SIO_ID_SPI0;
192 serialio_d21_ltr(bar0);
193 serialio_d21_mode(sio_index, SIO_PIN_INTC,
194 config->sio_acpi_mode);
195 break;
196 case PCI_DEVFN(21, 4): /* SPI1 */
197 sio_index = SIO_ID_SPI1;
198 serialio_d21_ltr(bar0);
199 serialio_d21_mode(sio_index, SIO_PIN_INTC,
200 config->sio_acpi_mode);
201 break;
202 case PCI_DEVFN(21, 5): /* UART0 */
203 sio_index = SIO_ID_UART0;
204 serialio_d21_ltr(bar0);
205 serialio_d21_mode(sio_index, SIO_PIN_INTD,
206 config->sio_acpi_mode);
207 break;
208 case PCI_DEVFN(21, 6): /* UART1 */
209 sio_index = SIO_ID_UART1;
210 serialio_d21_ltr(bar0);
211 serialio_d21_mode(sio_index, SIO_PIN_INTD,
212 config->sio_acpi_mode);
213 break;
214 case PCI_DEVFN(23, 0): /* SDIO */
215 sio_index = SIO_ID_SDIO;
216 serialio_d23_ltr(bar0);
217 serialio_d23_mode(config->sio_acpi_mode);
218 break;
219 default:
220 return;
221 }
222
223 if (config->sio_acpi_mode) {
224 global_nvs_t *gnvs;
225
226 /* Find ACPI NVS to update BARs */
227 gnvs = (global_nvs_t *)cbmem_find(CBMEM_ID_ACPI_GNVS);
228 if (!gnvs) {
229 printk(BIOS_ERR, "Unable to locate Global NVS\n");
230 return;
231 }
232
233 /* Save BAR0 and BAR1 to ACPI NVS */
234 gnvs->s0b[sio_index] = (u32)bar0->base;
235 gnvs->s1b[sio_index] = (u32)bar1->base;
236 }
237}
238
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700239static struct pci_operations pci_ops = {
Subrata Banik4a0f0712019-03-20 14:29:47 +0530240 .set_subsystem = pci_dev_set_subsystem,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700241};
242
243static struct device_operations device_ops = {
Duncan Laurie98c40622013-05-21 16:37:40 -0700244 .read_resources = pci_dev_read_resources,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700245 .set_resources = pci_dev_set_resources,
Duncan Laurie98c40622013-05-21 16:37:40 -0700246 .enable_resources = pci_dev_enable_resources,
Duncan Laurieb39ba2e2013-03-22 11:21:14 -0700247 .init = serialio_init,
248 .ops_pci = &pci_ops,
249};
250
251static const unsigned short pci_device_ids[] = {
252 0x9c60, /* 0:15.0 - SDMA */
253 0x9c61, /* 0:15.1 - I2C0 */
254 0x9c62, /* 0:15.2 - I2C1 */
255 0x9c65, /* 0:15.3 - SPI0 */
256 0x9c66, /* 0:15.4 - SPI1 */
257 0x9c63, /* 0:15.5 - UART0 */
258 0x9c64, /* 0:15.6 - UART1 */
259 0x9c35, /* 0:17.0 - SDIO */
260 0
261};
262
263static const struct pci_driver pch_pcie __pci_driver = {
264 .ops = &device_ops,
265 .vendor = PCI_VENDOR_ID_INTEL,
266 .devices = pci_device_ids,
267};