blob: 4ffdca9d63fbc11d351ef2e6bb960981b241681a [file] [log] [blame]
Aaron Durbindc866cf2013-11-12 20:21:53 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of 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.
Aaron Durbindc866cf2013-11-12 20:21:53 -060014 */
15
16#include <stdint.h>
Duncan Laurie430bf0d2013-12-10 14:37:42 -080017#include <cbmem.h>
Aaron Durbindc866cf2013-11-12 20:21:53 -060018#include <console/console.h>
19#include <device/device.h>
20#include <device/pci.h>
21#include <device/pci_ids.h>
22#include <reg_script.h>
23
Julius Werner18ea2d32014-10-07 16:42:17 -070024#include <soc/iosf.h>
25#include <soc/nvs.h>
26#include <soc/pci_devs.h>
27#include <soc/ramstage.h>
Aaron Durbindc866cf2013-11-12 20:21:53 -060028
Duncan Laurie430bf0d2013-12-10 14:37:42 -080029#include "chip.h"
30
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020031static void dev_enable_acpi_mode(struct device *dev, int iosf_reg,
32 int nvs_index)
Duncan Laurie430bf0d2013-12-10 14:37:42 -080033{
34 struct reg_script ops[] = {
Duncan Laurie430bf0d2013-12-10 14:37:42 -080035 /* Disable PCI interrupt, enable Memory and Bus Master */
36 REG_PCI_OR32(PCI_COMMAND,
37 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | (1<<10)),
38 /* Enable ACPI mode */
39 REG_IOSF_OR(IOSF_PORT_LPSS, iosf_reg,
40 LPSS_CTL_PCI_CFG_DIS | LPSS_CTL_ACPI_INT_EN),
41 REG_SCRIPT_END
42 };
43 struct resource *bar;
44 global_nvs_t *gnvs;
45
46 /* Find ACPI NVS to update BARs */
47 gnvs = (global_nvs_t *)cbmem_find(CBMEM_ID_ACPI_GNVS);
48 if (!gnvs) {
49 printk(BIOS_ERR, "Unable to locate Global NVS\n");
50 return;
51 }
52
53 /* Save BAR0 and BAR1 to ACPI NVS */
54 bar = find_resource(dev, PCI_BASE_ADDRESS_0);
55 if (bar)
56 gnvs->dev.lpss_bar0[nvs_index] = (u32)bar->base;
57
58 bar = find_resource(dev, PCI_BASE_ADDRESS_1);
59 if (bar)
60 gnvs->dev.lpss_bar1[nvs_index] = (u32)bar->base;
61
62 /* Device is enabled in ACPI mode */
63 gnvs->dev.lpss_en[nvs_index] = 1;
64
65 /* Put device in ACPI mode */
Aaron Durbin616f3942013-12-10 17:12:44 -080066 reg_script_run_on_dev(dev, ops);
Duncan Laurie430bf0d2013-12-10 14:37:42 -080067}
Aaron Durbindc866cf2013-11-12 20:21:53 -060068
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020069static void dev_enable_snoop_and_pm(struct device *dev, int iosf_reg)
Aaron Durbindc866cf2013-11-12 20:21:53 -060070{
71 struct reg_script ops[] = {
Aaron Durbindc866cf2013-11-12 20:21:53 -060072 REG_IOSF_RMW(IOSF_PORT_LPSS, iosf_reg,
73 ~(LPSS_CTL_SNOOP | LPSS_CTL_NOSNOOP),
74 LPSS_CTL_SNOOP | LPSS_CTL_PM_CAP_PRSNT),
75 REG_SCRIPT_END,
76 };
77
Aaron Durbin616f3942013-12-10 17:12:44 -080078 reg_script_run_on_dev(dev, ops);
Aaron Durbindc866cf2013-11-12 20:21:53 -060079}
80
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020081static void dev_ctl_reg(struct device *dev, int *iosf_reg, int *nvs_index)
Aaron Durbindc866cf2013-11-12 20:21:53 -060082{
Duncan Laurie430bf0d2013-12-10 14:37:42 -080083 *iosf_reg = -1;
84 *nvs_index = -1;
Aaron Durbindc866cf2013-11-12 20:21:53 -060085#define SET_IOSF_REG(name_) \
86 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
Duncan Laurie430bf0d2013-12-10 14:37:42 -080087 *iosf_reg = LPSS_ ## name_ ## _CTL; \
88 *nvs_index = LPSS_NVS_ ## name_
Aaron Durbindc866cf2013-11-12 20:21:53 -060089
90 switch (dev->path.pci.devfn) {
91 SET_IOSF_REG(SIO_DMA1);
92 break;
93 SET_IOSF_REG(I2C1);
94 break;
95 SET_IOSF_REG(I2C2);
96 break;
97 SET_IOSF_REG(I2C3);
98 break;
99 SET_IOSF_REG(I2C4);
100 break;
101 SET_IOSF_REG(I2C5);
102 break;
103 SET_IOSF_REG(I2C6);
104 break;
105 SET_IOSF_REG(I2C7);
106 break;
107 SET_IOSF_REG(SIO_DMA2);
108 break;
109 SET_IOSF_REG(PWM1);
110 break;
111 SET_IOSF_REG(PWM2);
112 break;
113 SET_IOSF_REG(HSUART1);
114 break;
115 SET_IOSF_REG(HSUART2);
116 break;
117 SET_IOSF_REG(SPI);
118 break;
119 }
Aaron Durbindc866cf2013-11-12 20:21:53 -0600120}
121
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200122static void i2c_disable_resets(struct device *dev)
Aaron Durbindc866cf2013-11-12 20:21:53 -0600123{
124 /* Release the I2C devices from reset. */
Aaron Durbin616f3942013-12-10 17:12:44 -0800125 static const struct reg_script ops[] = {
Aaron Durbindc866cf2013-11-12 20:21:53 -0600126 REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x804, 0x3),
127 REG_SCRIPT_END,
128 };
129
130#define CASE_I2C(name_) \
131 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC)
132
133 switch (dev->path.pci.devfn) {
134 CASE_I2C(I2C1):
135 CASE_I2C(I2C2):
136 CASE_I2C(I2C3):
137 CASE_I2C(I2C4):
138 CASE_I2C(I2C5):
139 CASE_I2C(I2C6):
140 CASE_I2C(I2C7):
141 printk(BIOS_DEBUG, "Releasing I2C device from reset.\n");
Aaron Durbin616f3942013-12-10 17:12:44 -0800142 reg_script_run_on_dev(dev, ops);
Aaron Durbindc866cf2013-11-12 20:21:53 -0600143 break;
144 default:
145 return;
146 }
147}
148
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200149static void lpss_init(struct device *dev)
Aaron Durbindc866cf2013-11-12 20:21:53 -0600150{
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300151 struct soc_intel_baytrail_config *config = config_of(dev);
Duncan Laurie430bf0d2013-12-10 14:37:42 -0800152 int iosf_reg, nvs_index;
153
154 dev_ctl_reg(dev, &iosf_reg, &nvs_index);
Aaron Durbindc866cf2013-11-12 20:21:53 -0600155
156 if (iosf_reg < 0) {
157 int slot = PCI_SLOT(dev->path.pci.devfn);
158 int func = PCI_FUNC(dev->path.pci.devfn);
159 printk(BIOS_DEBUG, "Could not find iosf_reg for %02x.%01x\n",
160 slot, func);
161 return;
162 }
163 dev_enable_snoop_and_pm(dev, iosf_reg);
Duncan Lauriec29d6b82013-12-12 16:55:36 -0800164 i2c_disable_resets(dev);
Aaron Durbindc866cf2013-11-12 20:21:53 -0600165
Duncan Laurie430bf0d2013-12-10 14:37:42 -0800166 if (config->lpss_acpi_mode)
167 dev_enable_acpi_mode(dev, iosf_reg, nvs_index);
Aaron Durbindc866cf2013-11-12 20:21:53 -0600168}
169
170static struct device_operations device_ops = {
171 .read_resources = pci_dev_read_resources,
172 .set_resources = pci_dev_set_resources,
173 .enable_resources = pci_dev_enable_resources,
174 .init = lpss_init,
175 .enable = NULL,
176 .scan_bus = NULL,
177 .ops_pci = &soc_pci_ops,
178};
179
180static const unsigned short pci_device_ids[] = {
181 SIO_DMA1_DEVID,
182 I2C1_DEVID,
183 I2C2_DEVID,
184 I2C3_DEVID,
185 I2C4_DEVID,
186 I2C5_DEVID,
187 I2C6_DEVID,
188 I2C7_DEVID,
189 SIO_DMA2_DEVID,
190 PWM1_DEVID,
191 PWM2_DEVID,
192 HSUART1_DEVID,
193 HSUART2_DEVID,
194 SPI_DEVID,
195 0,
196};
197
198static const struct pci_driver southcluster __pci_driver = {
199 .ops = &device_ops,
200 .vendor = PCI_VENDOR_ID_INTEL,
201 .devices = pci_device_ids,
202};