Angel Pons | 0612b27 | 2020-04-05 15:46:56 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 4 | #include <device/pci_ops.h> |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 5 | #include <console/console.h> |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 6 | #include <device/pci.h> |
| 7 | #include <device/pci_ids.h> |
| 8 | #include <intelblocks/pmc.h> |
| 9 | #include <soc/pci_devs.h> |
| 10 | |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 11 | static void pch_pmc_add_new_resource(struct device *dev, |
| 12 | uint8_t offset, uintptr_t base, size_t size, |
| 13 | unsigned long flags) |
| 14 | { |
| 15 | struct resource *res; |
| 16 | res = new_resource(dev, offset); |
| 17 | res->base = base; |
| 18 | res->size = size; |
| 19 | res->flags = flags; |
| 20 | } |
| 21 | |
| 22 | static void pch_pmc_add_mmio_resources(struct device *dev, |
| 23 | const struct pmc_resource_config *cfg) |
| 24 | { |
| 25 | pch_pmc_add_new_resource(dev, cfg->pwrmbase_offset, |
| 26 | cfg->pwrmbase_addr, cfg->pwrmbase_size, |
| 27 | IORESOURCE_MEM | IORESOURCE_ASSIGNED | |
| 28 | IORESOURCE_FIXED | IORESOURCE_RESERVE); |
| 29 | } |
| 30 | |
| 31 | static void pch_pmc_add_io_resources(struct device *dev, |
| 32 | const struct pmc_resource_config *cfg) |
| 33 | { |
| 34 | pch_pmc_add_new_resource(dev, cfg->abase_offset, |
| 35 | cfg->abase_addr, cfg->abase_size, |
| 36 | IORESOURCE_IO | IORESOURCE_ASSIGNED | |
| 37 | IORESOURCE_FIXED); |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 38 | if (CONFIG(PMC_INVALID_READ_AFTER_WRITE)) { |
Hannah Williams | 1177bf5 | 2017-12-13 12:44:26 -0800 | [diff] [blame] | 39 | /* |
| 40 | * The ACPI IO BAR (offset 0x20) is not PCI compliant. We've |
| 41 | * observed cases where the BAR reads back as 0, but the IO |
| 42 | * window is open. This also means that it will not respond |
| 43 | * to PCI probing. |
| 44 | */ |
| 45 | pci_write_config16(dev, cfg->abase_offset, cfg->abase_addr); |
| 46 | /* |
| 47 | * In pci_dev_enable_resources, reading IO SPACE ACCESS bit in |
| 48 | * STATUSCOMMAND register does not read back the written |
| 49 | * value correctly, hence IO access gets disabled. This is |
| 50 | * seen in some PMC devices, hence this code makes sure |
| 51 | * IO access is available. |
| 52 | */ |
| 53 | dev->command |= PCI_COMMAND_IO; |
| 54 | } |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static void pch_pmc_read_resources(struct device *dev) |
| 58 | { |
| 59 | struct pmc_resource_config pmc_cfg; |
| 60 | struct pmc_resource_config *config = &pmc_cfg; |
| 61 | |
| 62 | if (pmc_soc_get_resources(config) < 0) |
Keith Short | 15588b0 | 2019-05-09 11:40:34 -0600 | [diff] [blame] | 63 | die_with_post_code(POST_HW_INIT_FAILURE, |
| 64 | "Unable to get PMC controller resource information!"); |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 65 | |
| 66 | /* Get the normal PCI resources of this device. */ |
| 67 | pci_dev_read_resources(dev); |
| 68 | |
| 69 | /* Add non-standard MMIO resources. */ |
| 70 | pch_pmc_add_mmio_resources(dev, config); |
| 71 | |
| 72 | /* Add IO resources. */ |
| 73 | pch_pmc_add_io_resources(dev, config); |
| 74 | } |
| 75 | |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 76 | static struct device_operations device_ops = { |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 77 | .read_resources = pch_pmc_read_resources, |
| 78 | .set_resources = pci_dev_set_resources, |
| 79 | .enable_resources = pci_dev_enable_resources, |
| 80 | .init = pmc_soc_init, |
Subrata Banik | 6bbc91a | 2017-12-07 14:55:51 +0530 | [diff] [blame] | 81 | .ops_pci = &pci_dev_ops_pci, |
Nico Huber | 51b75ae | 2019-03-14 16:02:05 +0100 | [diff] [blame] | 82 | .scan_bus = scan_static_bus, |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | static const unsigned short pci_device_ids[] = { |
| 86 | PCI_DEVICE_ID_INTEL_SPT_LP_PMC, |
V Sowmya | 7c15047 | 2018-01-23 14:44:45 +0530 | [diff] [blame] | 87 | PCI_DEVICE_ID_INTEL_SPT_H_PMC, |
Maxim Polyakov | 571d07d | 2019-08-22 13:11:32 +0300 | [diff] [blame] | 88 | PCI_DEVICE_ID_INTEL_LWB_PMC, |
| 89 | PCI_DEVICE_ID_INTEL_LWB_PMC_SUPER, |
Angel Pons | f530e36 | 2021-04-27 10:20:04 +0200 | [diff] [blame^] | 90 | PCI_DEVICE_ID_INTEL_UPT_H_PMC, |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 91 | PCI_DEVICE_ID_INTEL_APL_PMC, |
| 92 | PCI_DEVICE_ID_INTEL_GLK_PMC, |
praveen hodagatta pranesh | e26c4a4 | 2018-09-20 03:49:45 +0800 | [diff] [blame] | 93 | PCI_DEVICE_ID_INTEL_CNP_H_PMC, |
Aamir Bohra | 9eac039 | 2018-06-30 12:07:04 +0530 | [diff] [blame] | 94 | PCI_DEVICE_ID_INTEL_ICP_PMC, |
Ronak Kanabar | da7ffb48 | 2019-02-05 01:51:13 +0530 | [diff] [blame] | 95 | PCI_DEVICE_ID_INTEL_CMP_PMC, |
Gaggery Tsai | 12a651c | 2019-12-05 11:23:20 -0800 | [diff] [blame] | 96 | PCI_DEVICE_ID_INTEL_CMP_H_PMC, |
Ravi Sarawadi | 6b5bf40 | 2019-10-21 22:25:04 -0700 | [diff] [blame] | 97 | PCI_DEVICE_ID_INTEL_TGP_PMC, |
Tan, Lean Sheng | 2613609 | 2020-01-20 19:13:56 -0800 | [diff] [blame] | 98 | PCI_DEVICE_ID_INTEL_MCC_PMC, |
Meera Ravindranath | 3f4af0d | 2020-02-12 16:01:22 +0530 | [diff] [blame] | 99 | PCI_DEVICE_ID_INTEL_JSP_PMC, |
Subrata Banik | f672f7f | 2020-08-03 14:29:25 +0530 | [diff] [blame] | 100 | PCI_DEVICE_ID_INTEL_ADP_P_PMC, |
| 101 | PCI_DEVICE_ID_INTEL_ADP_S_PMC, |
Varshit Pandya | f4d98fdd2 | 2021-01-17 18:39:29 +0530 | [diff] [blame] | 102 | PCI_DEVICE_ID_INTEL_ADP_M_PMC, |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 103 | 0 |
| 104 | }; |
| 105 | |
Subrata Banik | 8885206 | 2018-01-10 10:51:50 +0530 | [diff] [blame] | 106 | static const struct pci_driver pch_pmc __pci_driver = { |
Subrata Banik | 2153ea5 | 2017-11-22 15:38:19 +0530 | [diff] [blame] | 107 | .ops = &device_ops, |
| 108 | .vendor = PCI_VENDOR_ID_INTEL, |
| 109 | .devices = pci_device_ids, |
| 110 | }; |