Angel Pons | c3f58f6 | 2020-04-05 15:46:41 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 3 | |
| 4 | #include <stdint.h> |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 5 | #include <cbmem.h> |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 6 | #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 Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 12 | #include <soc/iosf.h> |
| 13 | #include <soc/nvs.h> |
| 14 | #include <soc/pci_devs.h> |
| 15 | #include <soc/ramstage.h> |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 16 | |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 17 | #include "chip.h" |
| 18 | |
Elyes HAOUAS | 17a3ceb | 2018-05-22 10:42:28 +0200 | [diff] [blame] | 19 | static void dev_enable_acpi_mode(struct device *dev, int iosf_reg, |
| 20 | int nvs_index) |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 21 | { |
| 22 | struct reg_script ops[] = { |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 23 | /* 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 Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 54 | reg_script_run_on_dev(dev, ops); |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 55 | } |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 56 | |
Elyes HAOUAS | 17a3ceb | 2018-05-22 10:42:28 +0200 | [diff] [blame] | 57 | static void dev_enable_snoop_and_pm(struct device *dev, int iosf_reg) |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 58 | { |
| 59 | struct reg_script ops[] = { |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 60 | 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 Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 66 | reg_script_run_on_dev(dev, ops); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 67 | } |
| 68 | |
Elyes HAOUAS | 17a3ceb | 2018-05-22 10:42:28 +0200 | [diff] [blame] | 69 | static void dev_ctl_reg(struct device *dev, int *iosf_reg, int *nvs_index) |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 70 | { |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 71 | *iosf_reg = -1; |
| 72 | *nvs_index = -1; |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 73 | #define SET_IOSF_REG(name_) \ |
| 74 | case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \ |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 75 | *iosf_reg = LPSS_ ## name_ ## _CTL; \ |
| 76 | *nvs_index = LPSS_NVS_ ## name_ |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 77 | |
| 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 Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 108 | } |
| 109 | |
Elyes HAOUAS | 17a3ceb | 2018-05-22 10:42:28 +0200 | [diff] [blame] | 110 | static void i2c_disable_resets(struct device *dev) |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 111 | { |
| 112 | /* Release the I2C devices from reset. */ |
Aaron Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 113 | static const struct reg_script ops[] = { |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 114 | 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 Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 130 | reg_script_run_on_dev(dev, ops); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 131 | break; |
| 132 | default: |
| 133 | return; |
| 134 | } |
| 135 | } |
| 136 | |
Elyes HAOUAS | 17a3ceb | 2018-05-22 10:42:28 +0200 | [diff] [blame] | 137 | static void lpss_init(struct device *dev) |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 138 | { |
Kyösti Mälkki | 8950cfb | 2019-07-13 22:16:25 +0300 | [diff] [blame] | 139 | struct soc_intel_baytrail_config *config = config_of(dev); |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 140 | int iosf_reg, nvs_index; |
| 141 | |
| 142 | dev_ctl_reg(dev, &iosf_reg, &nvs_index); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 143 | |
| 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 Laurie | c29d6b8 | 2013-12-12 16:55:36 -0800 | [diff] [blame] | 152 | i2c_disable_resets(dev); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 153 | |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 154 | if (config->lpss_acpi_mode) |
| 155 | dev_enable_acpi_mode(dev, iosf_reg, nvs_index); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | static 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 Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 163 | .ops_pci = &soc_pci_ops, |
| 164 | }; |
| 165 | |
| 166 | static 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 | |
| 184 | static const struct pci_driver southcluster __pci_driver = { |
| 185 | .ops = &device_ops, |
| 186 | .vendor = PCI_VENDOR_ID_INTEL, |
| 187 | .devices = pci_device_ids, |
| 188 | }; |