Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 1 | /* |
| 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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <arch/io.h> |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 22 | #include <cbmem.h> |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 23 | #include <console/console.h> |
| 24 | #include <device/device.h> |
| 25 | #include <device/pci.h> |
| 26 | #include <device/pci_ids.h> |
| 27 | #include <reg_script.h> |
| 28 | |
Julius Werner | 18ea2d3 | 2014-10-07 16:42:17 -0700 | [diff] [blame^] | 29 | #include <soc/iosf.h> |
| 30 | #include <soc/nvs.h> |
| 31 | #include <soc/pci_devs.h> |
| 32 | #include <soc/ramstage.h> |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 33 | |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 34 | #include "chip.h" |
| 35 | |
| 36 | static void dev_enable_acpi_mode(device_t dev, int iosf_reg, int nvs_index) |
| 37 | { |
| 38 | struct reg_script ops[] = { |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 39 | /* Disable PCI interrupt, enable Memory and Bus Master */ |
| 40 | REG_PCI_OR32(PCI_COMMAND, |
| 41 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | (1<<10)), |
| 42 | /* Enable ACPI mode */ |
| 43 | REG_IOSF_OR(IOSF_PORT_LPSS, iosf_reg, |
| 44 | LPSS_CTL_PCI_CFG_DIS | LPSS_CTL_ACPI_INT_EN), |
| 45 | REG_SCRIPT_END |
| 46 | }; |
| 47 | struct resource *bar; |
| 48 | global_nvs_t *gnvs; |
| 49 | |
| 50 | /* Find ACPI NVS to update BARs */ |
| 51 | gnvs = (global_nvs_t *)cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 52 | if (!gnvs) { |
| 53 | printk(BIOS_ERR, "Unable to locate Global NVS\n"); |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | /* Save BAR0 and BAR1 to ACPI NVS */ |
| 58 | bar = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 59 | if (bar) |
| 60 | gnvs->dev.lpss_bar0[nvs_index] = (u32)bar->base; |
| 61 | |
| 62 | bar = find_resource(dev, PCI_BASE_ADDRESS_1); |
| 63 | if (bar) |
| 64 | gnvs->dev.lpss_bar1[nvs_index] = (u32)bar->base; |
| 65 | |
| 66 | /* Device is enabled in ACPI mode */ |
| 67 | gnvs->dev.lpss_en[nvs_index] = 1; |
| 68 | |
| 69 | /* Put device in ACPI mode */ |
Aaron Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 70 | reg_script_run_on_dev(dev, ops); |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 71 | } |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 72 | |
| 73 | static void dev_enable_snoop_and_pm(device_t dev, int iosf_reg) |
| 74 | { |
| 75 | struct reg_script ops[] = { |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 76 | REG_IOSF_RMW(IOSF_PORT_LPSS, iosf_reg, |
| 77 | ~(LPSS_CTL_SNOOP | LPSS_CTL_NOSNOOP), |
| 78 | LPSS_CTL_SNOOP | LPSS_CTL_PM_CAP_PRSNT), |
| 79 | REG_SCRIPT_END, |
| 80 | }; |
| 81 | |
Aaron Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 82 | reg_script_run_on_dev(dev, ops); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 83 | } |
| 84 | |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 85 | static void dev_ctl_reg(device_t dev, int *iosf_reg, int *nvs_index) |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 86 | { |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 87 | *iosf_reg = -1; |
| 88 | *nvs_index = -1; |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 89 | #define SET_IOSF_REG(name_) \ |
| 90 | case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \ |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 91 | *iosf_reg = LPSS_ ## name_ ## _CTL; \ |
| 92 | *nvs_index = LPSS_NVS_ ## name_ |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 93 | |
| 94 | switch (dev->path.pci.devfn) { |
| 95 | SET_IOSF_REG(SIO_DMA1); |
| 96 | break; |
| 97 | SET_IOSF_REG(I2C1); |
| 98 | break; |
| 99 | SET_IOSF_REG(I2C2); |
| 100 | break; |
| 101 | SET_IOSF_REG(I2C3); |
| 102 | break; |
| 103 | SET_IOSF_REG(I2C4); |
| 104 | break; |
| 105 | SET_IOSF_REG(I2C5); |
| 106 | break; |
| 107 | SET_IOSF_REG(I2C6); |
| 108 | break; |
| 109 | SET_IOSF_REG(I2C7); |
| 110 | break; |
| 111 | SET_IOSF_REG(SIO_DMA2); |
| 112 | break; |
| 113 | SET_IOSF_REG(PWM1); |
| 114 | break; |
| 115 | SET_IOSF_REG(PWM2); |
| 116 | break; |
| 117 | SET_IOSF_REG(HSUART1); |
| 118 | break; |
| 119 | SET_IOSF_REG(HSUART2); |
| 120 | break; |
| 121 | SET_IOSF_REG(SPI); |
| 122 | break; |
| 123 | } |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static void i2c_disable_resets(device_t dev) |
| 127 | { |
| 128 | /* Release the I2C devices from reset. */ |
Aaron Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 129 | static const struct reg_script ops[] = { |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 130 | REG_RES_WRITE32(PCI_BASE_ADDRESS_0, 0x804, 0x3), |
| 131 | REG_SCRIPT_END, |
| 132 | }; |
| 133 | |
| 134 | #define CASE_I2C(name_) \ |
| 135 | case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC) |
| 136 | |
| 137 | switch (dev->path.pci.devfn) { |
| 138 | CASE_I2C(I2C1): |
| 139 | CASE_I2C(I2C2): |
| 140 | CASE_I2C(I2C3): |
| 141 | CASE_I2C(I2C4): |
| 142 | CASE_I2C(I2C5): |
| 143 | CASE_I2C(I2C6): |
| 144 | CASE_I2C(I2C7): |
| 145 | printk(BIOS_DEBUG, "Releasing I2C device from reset.\n"); |
Aaron Durbin | 616f394 | 2013-12-10 17:12:44 -0800 | [diff] [blame] | 146 | reg_script_run_on_dev(dev, ops); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 147 | break; |
| 148 | default: |
| 149 | return; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | static void lpss_init(device_t dev) |
| 154 | { |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 155 | struct soc_intel_baytrail_config *config = dev->chip_info; |
| 156 | int iosf_reg, nvs_index; |
| 157 | |
| 158 | dev_ctl_reg(dev, &iosf_reg, &nvs_index); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 159 | |
| 160 | if (iosf_reg < 0) { |
| 161 | int slot = PCI_SLOT(dev->path.pci.devfn); |
| 162 | int func = PCI_FUNC(dev->path.pci.devfn); |
| 163 | printk(BIOS_DEBUG, "Could not find iosf_reg for %02x.%01x\n", |
| 164 | slot, func); |
| 165 | return; |
| 166 | } |
| 167 | dev_enable_snoop_and_pm(dev, iosf_reg); |
Duncan Laurie | c29d6b8 | 2013-12-12 16:55:36 -0800 | [diff] [blame] | 168 | i2c_disable_resets(dev); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 169 | |
Duncan Laurie | 430bf0d | 2013-12-10 14:37:42 -0800 | [diff] [blame] | 170 | if (config->lpss_acpi_mode) |
| 171 | dev_enable_acpi_mode(dev, iosf_reg, nvs_index); |
Aaron Durbin | dc866cf | 2013-11-12 20:21:53 -0600 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static struct device_operations device_ops = { |
| 175 | .read_resources = pci_dev_read_resources, |
| 176 | .set_resources = pci_dev_set_resources, |
| 177 | .enable_resources = pci_dev_enable_resources, |
| 178 | .init = lpss_init, |
| 179 | .enable = NULL, |
| 180 | .scan_bus = NULL, |
| 181 | .ops_pci = &soc_pci_ops, |
| 182 | }; |
| 183 | |
| 184 | static const unsigned short pci_device_ids[] = { |
| 185 | SIO_DMA1_DEVID, |
| 186 | I2C1_DEVID, |
| 187 | I2C2_DEVID, |
| 188 | I2C3_DEVID, |
| 189 | I2C4_DEVID, |
| 190 | I2C5_DEVID, |
| 191 | I2C6_DEVID, |
| 192 | I2C7_DEVID, |
| 193 | SIO_DMA2_DEVID, |
| 194 | PWM1_DEVID, |
| 195 | PWM2_DEVID, |
| 196 | HSUART1_DEVID, |
| 197 | HSUART2_DEVID, |
| 198 | SPI_DEVID, |
| 199 | 0, |
| 200 | }; |
| 201 | |
| 202 | static const struct pci_driver southcluster __pci_driver = { |
| 203 | .ops = &device_ops, |
| 204 | .vendor = PCI_VENDOR_ID_INTEL, |
| 205 | .devices = pci_device_ids, |
| 206 | }; |