blob: d5c3e4de31495afb89d5c64592a6c5fa05b07e62 [file] [log] [blame]
Angel Ponsc3f58f62020-04-05 15:46:41 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbindc866cf2013-11-12 20:21:53 -06002
3#include <stdint.h>
Kyösti Mälkki5daa1d32020-06-14 12:01:58 +03004#include <acpi/acpi_gnvs.h>
Aaron Durbindc866cf2013-11-12 20:21:53 -06005#include <console/console.h>
6#include <device/device.h>
7#include <device/pci.h>
8#include <device/pci_ids.h>
9#include <reg_script.h>
10
Julius Werner18ea2d32014-10-07 16:42:17 -070011#include <soc/iosf.h>
12#include <soc/nvs.h>
13#include <soc/pci_devs.h>
14#include <soc/ramstage.h>
Aaron Durbindc866cf2013-11-12 20:21:53 -060015
Duncan Laurie430bf0d2013-12-10 14:37:42 -080016#include "chip.h"
17
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020018static void dev_enable_acpi_mode(struct device *dev, int iosf_reg,
19 int nvs_index)
Duncan Laurie430bf0d2013-12-10 14:37:42 -080020{
21 struct reg_script ops[] = {
Duncan Laurie430bf0d2013-12-10 14:37:42 -080022 /* Disable PCI interrupt, enable Memory and Bus Master */
Elyes HAOUASd2bbc682020-04-29 10:12:33 +020023 REG_PCI_OR16(PCI_COMMAND,
Duncan Laurie430bf0d2013-12-10 14:37:42 -080024 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | (1<<10)),
25 /* Enable ACPI mode */
26 REG_IOSF_OR(IOSF_PORT_LPSS, iosf_reg,
27 LPSS_CTL_PCI_CFG_DIS | LPSS_CTL_ACPI_INT_EN),
28 REG_SCRIPT_END
29 };
30 struct resource *bar;
31 global_nvs_t *gnvs;
32
33 /* Find ACPI NVS to update BARs */
Kyösti Mälkki5daa1d32020-06-14 12:01:58 +030034 gnvs = acpi_get_gnvs();
35 if (!gnvs)
Duncan Laurie430bf0d2013-12-10 14:37:42 -080036 return;
Duncan Laurie430bf0d2013-12-10 14:37:42 -080037
38 /* Save BAR0 and BAR1 to ACPI NVS */
39 bar = find_resource(dev, PCI_BASE_ADDRESS_0);
40 if (bar)
41 gnvs->dev.lpss_bar0[nvs_index] = (u32)bar->base;
42
43 bar = find_resource(dev, PCI_BASE_ADDRESS_1);
44 if (bar)
45 gnvs->dev.lpss_bar1[nvs_index] = (u32)bar->base;
46
47 /* Device is enabled in ACPI mode */
48 gnvs->dev.lpss_en[nvs_index] = 1;
49
50 /* Put device in ACPI mode */
Aaron Durbin616f3942013-12-10 17:12:44 -080051 reg_script_run_on_dev(dev, ops);
Duncan Laurie430bf0d2013-12-10 14:37:42 -080052}
Aaron Durbindc866cf2013-11-12 20:21:53 -060053
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020054static void dev_enable_snoop_and_pm(struct device *dev, int iosf_reg)
Aaron Durbindc866cf2013-11-12 20:21:53 -060055{
56 struct reg_script ops[] = {
Aaron Durbindc866cf2013-11-12 20:21:53 -060057 REG_IOSF_RMW(IOSF_PORT_LPSS, iosf_reg,
58 ~(LPSS_CTL_SNOOP | LPSS_CTL_NOSNOOP),
59 LPSS_CTL_SNOOP | LPSS_CTL_PM_CAP_PRSNT),
60 REG_SCRIPT_END,
61 };
62
Aaron Durbin616f3942013-12-10 17:12:44 -080063 reg_script_run_on_dev(dev, ops);
Aaron Durbindc866cf2013-11-12 20:21:53 -060064}
65
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020066static void dev_ctl_reg(struct device *dev, int *iosf_reg, int *nvs_index)
Aaron Durbindc866cf2013-11-12 20:21:53 -060067{
Duncan Laurie430bf0d2013-12-10 14:37:42 -080068 *iosf_reg = -1;
69 *nvs_index = -1;
Aaron Durbindc866cf2013-11-12 20:21:53 -060070#define SET_IOSF_REG(name_) \
71 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
Duncan Laurie430bf0d2013-12-10 14:37:42 -080072 *iosf_reg = LPSS_ ## name_ ## _CTL; \
73 *nvs_index = LPSS_NVS_ ## name_
Aaron Durbindc866cf2013-11-12 20:21:53 -060074
75 switch (dev->path.pci.devfn) {
76 SET_IOSF_REG(SIO_DMA1);
77 break;
78 SET_IOSF_REG(I2C1);
79 break;
80 SET_IOSF_REG(I2C2);
81 break;
82 SET_IOSF_REG(I2C3);
83 break;
84 SET_IOSF_REG(I2C4);
85 break;
86 SET_IOSF_REG(I2C5);
87 break;
88 SET_IOSF_REG(I2C6);
89 break;
90 SET_IOSF_REG(I2C7);
91 break;
92 SET_IOSF_REG(SIO_DMA2);
93 break;
94 SET_IOSF_REG(PWM1);
95 break;
96 SET_IOSF_REG(PWM2);
97 break;
98 SET_IOSF_REG(HSUART1);
99 break;
100 SET_IOSF_REG(HSUART2);
101 break;
102 SET_IOSF_REG(SPI);
103 break;
104 }
Aaron Durbindc866cf2013-11-12 20:21:53 -0600105}
106
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200107static void i2c_disable_resets(struct device *dev)
Aaron Durbindc866cf2013-11-12 20:21:53 -0600108{
109 /* Release the I2C devices from reset. */
Aaron Durbin616f3942013-12-10 17:12:44 -0800110 static const struct reg_script ops[] = {
Aaron Durbindc866cf2013-11-12 20:21:53 -0600111 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x804, 0x3),
112 REG_SCRIPT_END,
113 };
114
115#define CASE_I2C(name_) \
116 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC)
117
118 switch (dev->path.pci.devfn) {
119 CASE_I2C(I2C1):
120 CASE_I2C(I2C2):
121 CASE_I2C(I2C3):
122 CASE_I2C(I2C4):
123 CASE_I2C(I2C5):
124 CASE_I2C(I2C6):
125 CASE_I2C(I2C7):
126 printk(BIOS_DEBUG, "Releasing I2C device from reset.\n");
Aaron Durbin616f3942013-12-10 17:12:44 -0800127 reg_script_run_on_dev(dev, ops);
Aaron Durbindc866cf2013-11-12 20:21:53 -0600128 break;
129 default:
130 return;
131 }
132}
133
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200134static void lpss_init(struct device *dev)
Aaron Durbindc866cf2013-11-12 20:21:53 -0600135{
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300136 struct soc_intel_baytrail_config *config = config_of(dev);
Duncan Laurie430bf0d2013-12-10 14:37:42 -0800137 int iosf_reg, nvs_index;
138
139 dev_ctl_reg(dev, &iosf_reg, &nvs_index);
Aaron Durbindc866cf2013-11-12 20:21:53 -0600140
141 if (iosf_reg < 0) {
142 int slot = PCI_SLOT(dev->path.pci.devfn);
143 int func = PCI_FUNC(dev->path.pci.devfn);
144 printk(BIOS_DEBUG, "Could not find iosf_reg for %02x.%01x\n",
145 slot, func);
146 return;
147 }
148 dev_enable_snoop_and_pm(dev, iosf_reg);
Duncan Lauriec29d6b82013-12-12 16:55:36 -0800149 i2c_disable_resets(dev);
Aaron Durbindc866cf2013-11-12 20:21:53 -0600150
Duncan Laurie430bf0d2013-12-10 14:37:42 -0800151 if (config->lpss_acpi_mode)
152 dev_enable_acpi_mode(dev, iosf_reg, nvs_index);
Aaron Durbindc866cf2013-11-12 20:21:53 -0600153}
154
155static struct device_operations device_ops = {
156 .read_resources = pci_dev_read_resources,
157 .set_resources = pci_dev_set_resources,
158 .enable_resources = pci_dev_enable_resources,
159 .init = lpss_init,
Aaron Durbindc866cf2013-11-12 20:21:53 -0600160 .ops_pci = &soc_pci_ops,
161};
162
163static const unsigned short pci_device_ids[] = {
164 SIO_DMA1_DEVID,
165 I2C1_DEVID,
166 I2C2_DEVID,
167 I2C3_DEVID,
168 I2C4_DEVID,
169 I2C5_DEVID,
170 I2C6_DEVID,
171 I2C7_DEVID,
172 SIO_DMA2_DEVID,
173 PWM1_DEVID,
174 PWM2_DEVID,
175 HSUART1_DEVID,
176 HSUART2_DEVID,
177 SPI_DEVID,
178 0,
179};
180
181static const struct pci_driver southcluster __pci_driver = {
182 .ops = &device_ops,
183 .vendor = PCI_VENDOR_ID_INTEL,
184 .devices = pci_device_ids,
185};