Angel Pons | c3f58f6 | 2020-04-05 15:46:41 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 2 | |
| 3 | #include <stdint.h> |
Kyösti Mälkki | 5daa1d3 | 2020-06-14 12:01:58 +0300 | [diff] [blame] | 4 | #include <acpi/acpi_gnvs.h> |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 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> |
| 10 | |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame] | 11 | #include <soc/iosf.h> |
| 12 | #include <soc/nvs.h> |
| 13 | #include <soc/pci_devs.h> |
| 14 | #include <soc/ramstage.h> |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 15 | |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 16 | #include "chip.h" |
| 17 | |
Angel Pons | 41b1edf | 2020-07-07 17:54:56 +0200 | [diff] [blame] | 18 | static void dev_enable_acpi_mode(struct device *dev, int iosf_reg, int nvs_index) |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 19 | { |
| 20 | struct reg_script ops[] = { |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 21 | /* Disable PCI interrupt, enable Memory and Bus Master */ |
Angel Pons | 41b1edf | 2020-07-07 17:54:56 +0200 | [diff] [blame] | 22 | REG_PCI_OR16(PCI_COMMAND, PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | (1 << 10)), |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 23 | /* Enable ACPI mode */ |
| 24 | REG_IOSF_OR(IOSF_PORT_LPSS, iosf_reg, |
| 25 | LPSS_CTL_PCI_CFG_DIS | LPSS_CTL_ACPI_INT_EN), |
Angel Pons | 41b1edf | 2020-07-07 17:54:56 +0200 | [diff] [blame] | 26 | |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 27 | REG_SCRIPT_END |
| 28 | }; |
| 29 | struct resource *bar; |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 30 | struct global_nvs *gnvs; |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 31 | |
| 32 | /* Find ACPI NVS to update BARs */ |
Kyösti Mälkki | 5daa1d3 | 2020-06-14 12:01:58 +0300 | [diff] [blame] | 33 | gnvs = acpi_get_gnvs(); |
| 34 | if (!gnvs) |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 35 | return; |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 36 | |
| 37 | /* Save BAR0 and BAR1 to ACPI NVS */ |
| 38 | bar = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 39 | if (bar) |
| 40 | gnvs->dev.lpss_bar0[nvs_index] = (u32)bar->base; |
| 41 | |
| 42 | bar = find_resource(dev, PCI_BASE_ADDRESS_1); |
| 43 | if (bar) |
| 44 | gnvs->dev.lpss_bar1[nvs_index] = (u32)bar->base; |
| 45 | |
| 46 | /* Device is enabled in ACPI mode */ |
| 47 | gnvs->dev.lpss_en[nvs_index] = 1; |
| 48 | |
| 49 | /* Put device in ACPI mode */ |
Aaron Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 50 | reg_script_run_on_dev(dev, ops); |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 51 | } |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 52 | |
Elyes HAOUAS | 17a3ceb | 2018-05-22 10:42:28 +0200 | [diff] [blame] | 53 | 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] | 54 | { |
| 55 | struct reg_script ops[] = { |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 56 | REG_IOSF_RMW(IOSF_PORT_LPSS, iosf_reg, |
| 57 | ~(LPSS_CTL_SNOOP | LPSS_CTL_NOSNOOP), |
| 58 | LPSS_CTL_SNOOP | LPSS_CTL_PM_CAP_PRSNT), |
| 59 | REG_SCRIPT_END, |
| 60 | }; |
| 61 | |
Aaron Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 62 | reg_script_run_on_dev(dev, ops); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 63 | } |
| 64 | |
Angel Pons | 41b1edf | 2020-07-07 17:54:56 +0200 | [diff] [blame] | 65 | #define SET_IOSF_REG(name_) \ |
| 66 | case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \ |
| 67 | do { \ |
| 68 | *iosf_reg = LPSS_ ## name_ ## _CTL; \ |
| 69 | *nvs_index = LPSS_NVS_ ## name_; \ |
| 70 | } while (0) |
| 71 | |
Elyes HAOUAS | 17a3ceb | 2018-05-22 10:42:28 +0200 | [diff] [blame] | 72 | 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] | 73 | { |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 74 | *iosf_reg = -1; |
| 75 | *nvs_index = -1; |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 76 | |
| 77 | switch (dev->path.pci.devfn) { |
| 78 | SET_IOSF_REG(SIO_DMA1); |
| 79 | break; |
| 80 | SET_IOSF_REG(I2C1); |
| 81 | break; |
| 82 | SET_IOSF_REG(I2C2); |
| 83 | break; |
| 84 | SET_IOSF_REG(I2C3); |
| 85 | break; |
| 86 | SET_IOSF_REG(I2C4); |
| 87 | break; |
| 88 | SET_IOSF_REG(I2C5); |
| 89 | break; |
| 90 | SET_IOSF_REG(I2C6); |
| 91 | break; |
| 92 | SET_IOSF_REG(I2C7); |
| 93 | break; |
| 94 | SET_IOSF_REG(SIO_DMA2); |
| 95 | break; |
| 96 | SET_IOSF_REG(PWM1); |
| 97 | break; |
| 98 | SET_IOSF_REG(PWM2); |
| 99 | break; |
| 100 | SET_IOSF_REG(HSUART1); |
| 101 | break; |
| 102 | SET_IOSF_REG(HSUART2); |
| 103 | break; |
| 104 | SET_IOSF_REG(SPI); |
| 105 | break; |
| 106 | } |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 107 | } |
| 108 | |
Angel Pons | 41b1edf | 2020-07-07 17:54:56 +0200 | [diff] [blame] | 109 | #define CASE_I2C(name_) case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC) |
| 110 | |
Elyes HAOUAS | 17a3ceb | 2018-05-22 10:42:28 +0200 | [diff] [blame] | 111 | static void i2c_disable_resets(struct device *dev) |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 112 | { |
| 113 | /* Release the I2C devices from reset. */ |
Aaron Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 114 | static const struct reg_script ops[] = { |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 115 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x804, 0x3), |
| 116 | REG_SCRIPT_END, |
| 117 | }; |
| 118 | |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 119 | switch (dev->path.pci.devfn) { |
| 120 | CASE_I2C(I2C1): |
| 121 | CASE_I2C(I2C2): |
| 122 | CASE_I2C(I2C3): |
| 123 | CASE_I2C(I2C4): |
| 124 | CASE_I2C(I2C5): |
| 125 | CASE_I2C(I2C6): |
| 126 | CASE_I2C(I2C7): |
| 127 | printk(BIOS_DEBUG, "Releasing I2C device from reset.\n"); |
Aaron Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 128 | reg_script_run_on_dev(dev, ops); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 129 | break; |
| 130 | default: |
| 131 | return; |
| 132 | } |
| 133 | } |
| 134 | |
Elyes HAOUAS | 17a3ceb | 2018-05-22 10:42:28 +0200 | [diff] [blame] | 135 | static void lpss_init(struct device *dev) |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 136 | { |
Kyösti Mälkki | 8950cfb | 2019-07-13 22:16:25 +0300 | [diff] [blame] | 137 | struct soc_intel_baytrail_config *config = config_of(dev); |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 138 | int iosf_reg, nvs_index; |
| 139 | |
| 140 | dev_ctl_reg(dev, &iosf_reg, &nvs_index); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 141 | |
| 142 | if (iosf_reg < 0) { |
| 143 | int slot = PCI_SLOT(dev->path.pci.devfn); |
| 144 | int func = PCI_FUNC(dev->path.pci.devfn); |
Angel Pons | 41b1edf | 2020-07-07 17:54:56 +0200 | [diff] [blame] | 145 | printk(BIOS_DEBUG, "Could not find iosf_reg for %02x.%01x\n", slot, func); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 146 | return; |
| 147 | } |
| 148 | dev_enable_snoop_and_pm(dev, iosf_reg); |
Duncan Laurie | c29d6b8 | 2013-12-12 16:55:36 -0800 | [diff] [blame] | 149 | i2c_disable_resets(dev); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 150 | |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 151 | if (config->lpss_acpi_mode) |
| 152 | dev_enable_acpi_mode(dev, iosf_reg, nvs_index); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static 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 Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 160 | .ops_pci = &soc_pci_ops, |
| 161 | }; |
| 162 | |
| 163 | static 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 | |
| 181 | static const struct pci_driver southcluster __pci_driver = { |
| 182 | .ops = &device_ops, |
| 183 | .vendor = PCI_VENDOR_ID_INTEL, |
| 184 | .devices = pci_device_ids, |
| 185 | }; |