1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <acpi/acpi_gnvs.h>
5 #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>
12 #include <soc/device_nvs.h>
13 #include <soc/pci_devs.h>
14 #include <soc/ramstage.h>
18 static void dev_enable_acpi_mode(struct device
*dev
, int iosf_reg
, int nvs_index
)
20 struct reg_script ops
[] = {
21 /* Disable PCI interrupt, enable Memory and Bus Master */
22 REG_PCI_OR16(PCI_COMMAND
,
23 PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
| PCI_COMMAND_INT_DISABLE
),
24 /* Enable ACPI mode */
25 REG_IOSF_OR(IOSF_PORT_LPSS
, iosf_reg
,
26 LPSS_CTL_PCI_CFG_DIS
| LPSS_CTL_ACPI_INT_EN
),
31 struct device_nvs
*dev_nvs
= acpi_get_device_nvs();
33 /* Save BAR0 and BAR1 to ACPI NVS */
34 bar
= probe_resource(dev
, PCI_BASE_ADDRESS_0
);
36 dev_nvs
->lpss_bar0
[nvs_index
] = (u32
)bar
->base
;
38 bar
= probe_resource(dev
, PCI_BASE_ADDRESS_1
);
40 dev_nvs
->lpss_bar1
[nvs_index
] = (u32
)bar
->base
;
42 /* Device is enabled in ACPI mode */
43 dev_nvs
->lpss_en
[nvs_index
] = 1;
45 /* Put device in ACPI mode */
46 reg_script_run_on_dev(dev
, ops
);
49 #define SET_IOSF_REG(name_) \
50 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
52 *iosf_reg = LPSS_ ## name_ ## _CTL; \
53 *nvs_index = LPSS_NVS_ ## name_; \
56 static void dev_ctl_reg(struct device
*dev
, int *iosf_reg
, int *nvs_index
)
61 switch (dev
->path
.pci
.devfn
) {
62 SET_IOSF_REG(SIO_DMA1
);
78 SET_IOSF_REG(SIO_DMA2
);
84 SET_IOSF_REG(HSUART1
);
86 SET_IOSF_REG(HSUART2
);
93 #define CASE_I2C(name_) case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC)
95 static void i2c_disable_resets(struct device
*dev
)
97 /* Release the I2C devices from reset. */
98 static const struct reg_script ops
[] = {
99 REG_RES_WRITE32(PCI_BASE_ADDRESS_0
, 0x804, 0x3),
103 switch (dev
->path
.pci
.devfn
) {
111 printk(BIOS_DEBUG
, "Releasing I2C device from reset.\n");
112 reg_script_run_on_dev(dev
, ops
);
119 static void lpss_init(struct device
*dev
)
121 struct soc_intel_braswell_config
*config
= config_of(dev
);
122 int iosf_reg
, nvs_index
;
124 dev_ctl_reg(dev
, &iosf_reg
, &nvs_index
);
127 int slot
= PCI_SLOT(dev
->path
.pci
.devfn
);
128 int func
= PCI_FUNC(dev
->path
.pci
.devfn
);
129 printk(BIOS_DEBUG
, "Could not find iosf_reg for %02x.%01x\n", slot
, func
);
133 i2c_disable_resets(dev
);
135 if (config
->lpss_acpi_mode
)
136 dev_enable_acpi_mode(dev
, iosf_reg
, nvs_index
);
139 static struct device_operations device_ops
= {
140 .read_resources
= pci_dev_read_resources
,
141 .set_resources
= pci_dev_set_resources
,
142 .enable_resources
= pci_dev_enable_resources
,
144 .ops_pci
= &soc_pci_ops
,
147 static const unsigned short pci_device_ids
[] = {
165 static const struct pci_driver southcluster __pci_driver
= {
167 .vendor
= PCI_VID_INTEL
,
168 .devices
= pci_device_ids
,