blob: a01310e70ae0a3821775a96a020182afd24d19d5 [file] [log] [blame]
Angel Ponsc3f58f62020-04-05 15:46:41 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Aaron Durbindc866cf2013-11-12 20:21:53 -06003
4#include <stdint.h>
Duncan Laurie430bf0d2013-12-10 14:37:42 -08005#include <cbmem.h>
Aaron Durbindc866cf2013-11-12 20:21:53 -06006#include <console/console.h>
7#include <device/device.h>
8#include <device/pci.h>
9#include <device/pci_ids.h>
10#include <reg_script.h>
11
Julius Werner18ea2d32014-10-07 16:42:17 -070012#include <soc/iosf.h>
13#include <soc/nvs.h>
14#include <soc/pci_devs.h>
15#include <soc/ramstage.h>
Aaron Durbindc866cf2013-11-12 20:21:53 -060016
Duncan Laurie430bf0d2013-12-10 14:37:42 -080017#include "chip.h"
18
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020019static void dev_enable_acpi_mode(struct device *dev, int iosf_reg,
20 int nvs_index)
Duncan Laurie430bf0d2013-12-10 14:37:42 -080021{
22 struct reg_script ops[] = {
Duncan Laurie430bf0d2013-12-10 14:37:42 -080023 /* Disable PCI interrupt, enable Memory and Bus Master */
24 REG_PCI_OR32(PCI_COMMAND,
25 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | (1<<10)),
26 /* Enable ACPI mode */
27 REG_IOSF_OR(IOSF_PORT_LPSS, iosf_reg,
28 LPSS_CTL_PCI_CFG_DIS | LPSS_CTL_ACPI_INT_EN),
29 REG_SCRIPT_END
30 };
31 struct resource *bar;
32 global_nvs_t *gnvs;
33
34 /* Find ACPI NVS to update BARs */
35 gnvs = (global_nvs_t *)cbmem_find(CBMEM_ID_ACPI_GNVS);
36 if (!gnvs) {
37 printk(BIOS_ERR, "Unable to locate Global NVS\n");
38 return;
39 }
40
41 /* Save BAR0 and BAR1 to ACPI NVS */
42 bar = find_resource(dev, PCI_BASE_ADDRESS_0);
43 if (bar)
44 gnvs->dev.lpss_bar0[nvs_index] = (u32)bar->base;
45
46 bar = find_resource(dev, PCI_BASE_ADDRESS_1);
47 if (bar)
48 gnvs->dev.lpss_bar1[nvs_index] = (u32)bar->base;
49
50 /* Device is enabled in ACPI mode */
51 gnvs->dev.lpss_en[nvs_index] = 1;
52
53 /* Put device in ACPI mode */
Aaron Durbin616f3942013-12-10 17:12:44 -080054 reg_script_run_on_dev(dev, ops);
Duncan Laurie430bf0d2013-12-10 14:37:42 -080055}
Aaron Durbindc866cf2013-11-12 20:21:53 -060056
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020057static void dev_enable_snoop_and_pm(struct device *dev, int iosf_reg)
Aaron Durbindc866cf2013-11-12 20:21:53 -060058{
59 struct reg_script ops[] = {
Aaron Durbindc866cf2013-11-12 20:21:53 -060060 REG_IOSF_RMW(IOSF_PORT_LPSS, iosf_reg,
61 ~(LPSS_CTL_SNOOP | LPSS_CTL_NOSNOOP),
62 LPSS_CTL_SNOOP | LPSS_CTL_PM_CAP_PRSNT),
63 REG_SCRIPT_END,
64 };
65
Aaron Durbin616f3942013-12-10 17:12:44 -080066 reg_script_run_on_dev(dev, ops);
Aaron Durbindc866cf2013-11-12 20:21:53 -060067}
68
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020069static void dev_ctl_reg(struct device *dev, int *iosf_reg, int *nvs_index)
Aaron Durbindc866cf2013-11-12 20:21:53 -060070{
Duncan Laurie430bf0d2013-12-10 14:37:42 -080071 *iosf_reg = -1;
72 *nvs_index = -1;
Aaron Durbindc866cf2013-11-12 20:21:53 -060073#define SET_IOSF_REG(name_) \
74 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
Duncan Laurie430bf0d2013-12-10 14:37:42 -080075 *iosf_reg = LPSS_ ## name_ ## _CTL; \
76 *nvs_index = LPSS_NVS_ ## name_
Aaron Durbindc866cf2013-11-12 20:21:53 -060077
78 switch (dev->path.pci.devfn) {
79 SET_IOSF_REG(SIO_DMA1);
80 break;
81 SET_IOSF_REG(I2C1);
82 break;
83 SET_IOSF_REG(I2C2);
84 break;
85 SET_IOSF_REG(I2C3);
86 break;
87 SET_IOSF_REG(I2C4);
88 break;
89 SET_IOSF_REG(I2C5);
90 break;
91 SET_IOSF_REG(I2C6);
92 break;
93 SET_IOSF_REG(I2C7);
94 break;
95 SET_IOSF_REG(SIO_DMA2);
96 break;
97 SET_IOSF_REG(PWM1);
98 break;
99 SET_IOSF_REG(PWM2);
100 break;
101 SET_IOSF_REG(HSUART1);
102 break;
103 SET_IOSF_REG(HSUART2);
104 break;
105 SET_IOSF_REG(SPI);
106 break;
107 }
Aaron Durbindc866cf2013-11-12 20:21:53 -0600108}
109
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200110static void i2c_disable_resets(struct device *dev)
Aaron Durbindc866cf2013-11-12 20:21:53 -0600111{
112 /* Release the I2C devices from reset. */
Aaron Durbin616f3942013-12-10 17:12:44 -0800113 static const struct reg_script ops[] = {
Aaron Durbindc866cf2013-11-12 20:21:53 -0600114 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x804, 0x3),
115 REG_SCRIPT_END,
116 };
117
118#define CASE_I2C(name_) \
119 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC)
120
121 switch (dev->path.pci.devfn) {
122 CASE_I2C(I2C1):
123 CASE_I2C(I2C2):
124 CASE_I2C(I2C3):
125 CASE_I2C(I2C4):
126 CASE_I2C(I2C5):
127 CASE_I2C(I2C6):
128 CASE_I2C(I2C7):
129 printk(BIOS_DEBUG, "Releasing I2C device from reset.\n");
Aaron Durbin616f3942013-12-10 17:12:44 -0800130 reg_script_run_on_dev(dev, ops);
Aaron Durbindc866cf2013-11-12 20:21:53 -0600131 break;
132 default:
133 return;
134 }
135}
136
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200137static void lpss_init(struct device *dev)
Aaron Durbindc866cf2013-11-12 20:21:53 -0600138{
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300139 struct soc_intel_baytrail_config *config = config_of(dev);
Duncan Laurie430bf0d2013-12-10 14:37:42 -0800140 int iosf_reg, nvs_index;
141
142 dev_ctl_reg(dev, &iosf_reg, &nvs_index);
Aaron Durbindc866cf2013-11-12 20:21:53 -0600143
144 if (iosf_reg < 0) {
145 int slot = PCI_SLOT(dev->path.pci.devfn);
146 int func = PCI_FUNC(dev->path.pci.devfn);
147 printk(BIOS_DEBUG, "Could not find iosf_reg for %02x.%01x\n",
148 slot, func);
149 return;
150 }
151 dev_enable_snoop_and_pm(dev, iosf_reg);
Duncan Lauriec29d6b82013-12-12 16:55:36 -0800152 i2c_disable_resets(dev);
Aaron Durbindc866cf2013-11-12 20:21:53 -0600153
Duncan Laurie430bf0d2013-12-10 14:37:42 -0800154 if (config->lpss_acpi_mode)
155 dev_enable_acpi_mode(dev, iosf_reg, nvs_index);
Aaron Durbindc866cf2013-11-12 20:21:53 -0600156}
157
158static struct device_operations device_ops = {
159 .read_resources = pci_dev_read_resources,
160 .set_resources = pci_dev_set_resources,
161 .enable_resources = pci_dev_enable_resources,
162 .init = lpss_init,
Aaron Durbindc866cf2013-11-12 20:21:53 -0600163 .ops_pci = &soc_pci_ops,
164};
165
166static const unsigned short pci_device_ids[] = {
167 SIO_DMA1_DEVID,
168 I2C1_DEVID,
169 I2C2_DEVID,
170 I2C3_DEVID,
171 I2C4_DEVID,
172 I2C5_DEVID,
173 I2C6_DEVID,
174 I2C7_DEVID,
175 SIO_DMA2_DEVID,
176 PWM1_DEVID,
177 PWM2_DEVID,
178 HSUART1_DEVID,
179 HSUART2_DEVID,
180 SPI_DEVID,
181 0,
182};
183
184static const struct pci_driver southcluster __pci_driver = {
185 .ops = &device_ops,
186 .vendor = PCI_VENDOR_ID_INTEL,
187 .devices = pci_device_ids,
188};