blob: 24f28e33b7bc8fa55c6dcf2a69b41356cc284e7b [file] [log] [blame]
Angel Pons0612b272020-04-05 15:46:56 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Subrata Banik2153ea52017-11-22 15:38:19 +05302
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
Subrata Banik2153ea52017-11-22 15:38:19 +05304#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Subrata Banik2153ea52017-11-22 15:38:19 +05306#include <console/console.h>
7#include <cpu/x86/smm.h>
8#include <device/pci.h>
9#include <device/pci_ids.h>
10#include <intelblocks/pmc.h>
11#include <soc/pci_devs.h>
12
13/* SoC overrides */
14
15/* Fill up PMC resource structure inside SoC directory */
Aaron Durbin64031672018-04-21 14:45:32 -060016__weak int pmc_soc_get_resources(
Subrata Banik2153ea52017-11-22 15:38:19 +053017 struct pmc_resource_config *cfg)
18{
19 /* no-op */
20 return -1;
21}
22
23/* SoC override PMC initialization */
Aaron Durbin64031672018-04-21 14:45:32 -060024__weak void pmc_soc_init(struct device *dev)
Subrata Banik2153ea52017-11-22 15:38:19 +053025{
26 /* no-op */
27}
28
29static void pch_pmc_add_new_resource(struct device *dev,
30 uint8_t offset, uintptr_t base, size_t size,
31 unsigned long flags)
32{
33 struct resource *res;
34 res = new_resource(dev, offset);
35 res->base = base;
36 res->size = size;
37 res->flags = flags;
38}
39
40static void pch_pmc_add_mmio_resources(struct device *dev,
41 const struct pmc_resource_config *cfg)
42{
43 pch_pmc_add_new_resource(dev, cfg->pwrmbase_offset,
44 cfg->pwrmbase_addr, cfg->pwrmbase_size,
45 IORESOURCE_MEM | IORESOURCE_ASSIGNED |
46 IORESOURCE_FIXED | IORESOURCE_RESERVE);
47}
48
49static void pch_pmc_add_io_resources(struct device *dev,
50 const struct pmc_resource_config *cfg)
51{
52 pch_pmc_add_new_resource(dev, cfg->abase_offset,
53 cfg->abase_addr, cfg->abase_size,
54 IORESOURCE_IO | IORESOURCE_ASSIGNED |
55 IORESOURCE_FIXED);
Julius Wernercd49cce2019-03-05 16:53:33 -080056 if (CONFIG(PMC_INVALID_READ_AFTER_WRITE)) {
Hannah Williams1177bf52017-12-13 12:44:26 -080057 /*
58 * The ACPI IO BAR (offset 0x20) is not PCI compliant. We've
59 * observed cases where the BAR reads back as 0, but the IO
60 * window is open. This also means that it will not respond
61 * to PCI probing.
62 */
63 pci_write_config16(dev, cfg->abase_offset, cfg->abase_addr);
64 /*
65 * In pci_dev_enable_resources, reading IO SPACE ACCESS bit in
66 * STATUSCOMMAND register does not read back the written
67 * value correctly, hence IO access gets disabled. This is
68 * seen in some PMC devices, hence this code makes sure
69 * IO access is available.
70 */
71 dev->command |= PCI_COMMAND_IO;
72 }
Subrata Banik2153ea52017-11-22 15:38:19 +053073}
74
75static void pch_pmc_read_resources(struct device *dev)
76{
77 struct pmc_resource_config pmc_cfg;
78 struct pmc_resource_config *config = &pmc_cfg;
79
80 if (pmc_soc_get_resources(config) < 0)
Keith Short15588b02019-05-09 11:40:34 -060081 die_with_post_code(POST_HW_INIT_FAILURE,
82 "Unable to get PMC controller resource information!");
Subrata Banik2153ea52017-11-22 15:38:19 +053083
84 /* Get the normal PCI resources of this device. */
85 pci_dev_read_resources(dev);
86
87 /* Add non-standard MMIO resources. */
88 pch_pmc_add_mmio_resources(dev, config);
89
90 /* Add IO resources. */
91 pch_pmc_add_io_resources(dev, config);
92}
93
94void pmc_set_acpi_mode(void)
95{
Kyösti Mälkkiad882c32020-06-02 05:05:30 +030096 if (!acpi_is_wakeup_s3()) {
Kyösti Mälkkib6585482020-06-01 15:11:14 +030097 apm_control(APM_CNT_ACPI_DISABLE);
Subrata Banik2153ea52017-11-22 15:38:19 +053098 }
99}
100
101static struct device_operations device_ops = {
Elyes HAOUAS1d191272018-11-27 12:23:48 +0100102 .read_resources = pch_pmc_read_resources,
103 .set_resources = pci_dev_set_resources,
104 .enable_resources = pci_dev_enable_resources,
105 .init = pmc_soc_init,
Subrata Banik6bbc91a2017-12-07 14:55:51 +0530106 .ops_pci = &pci_dev_ops_pci,
Nico Huber51b75ae2019-03-14 16:02:05 +0100107 .scan_bus = scan_static_bus,
Subrata Banik2153ea52017-11-22 15:38:19 +0530108};
109
110static const unsigned short pci_device_ids[] = {
111 PCI_DEVICE_ID_INTEL_SPT_LP_PMC,
V Sowmya7c150472018-01-23 14:44:45 +0530112 PCI_DEVICE_ID_INTEL_SPT_H_PMC,
Maxim Polyakov571d07d2019-08-22 13:11:32 +0300113 PCI_DEVICE_ID_INTEL_LWB_PMC,
114 PCI_DEVICE_ID_INTEL_LWB_PMC_SUPER,
V Sowmyaacc2a482018-01-23 15:27:23 +0530115 PCI_DEVICE_ID_INTEL_KBP_H_PMC,
Subrata Banik2153ea52017-11-22 15:38:19 +0530116 PCI_DEVICE_ID_INTEL_APL_PMC,
117 PCI_DEVICE_ID_INTEL_GLK_PMC,
praveen hodagatta praneshe26c4a42018-09-20 03:49:45 +0800118 PCI_DEVICE_ID_INTEL_CNP_H_PMC,
Aamir Bohra9eac0392018-06-30 12:07:04 +0530119 PCI_DEVICE_ID_INTEL_ICP_PMC,
Ronak Kanabarda7ffb482019-02-05 01:51:13 +0530120 PCI_DEVICE_ID_INTEL_CMP_PMC,
Gaggery Tsai12a651c2019-12-05 11:23:20 -0800121 PCI_DEVICE_ID_INTEL_CMP_H_PMC,
Ravi Sarawadi6b5bf402019-10-21 22:25:04 -0700122 PCI_DEVICE_ID_INTEL_TGP_PMC,
Tan, Lean Sheng26136092020-01-20 19:13:56 -0800123 PCI_DEVICE_ID_INTEL_MCC_PMC,
Meera Ravindranath3f4af0d2020-02-12 16:01:22 +0530124 PCI_DEVICE_ID_INTEL_JSP_PMC,
Subrata Banikf672f7f2020-08-03 14:29:25 +0530125 PCI_DEVICE_ID_INTEL_ADP_P_PMC,
126 PCI_DEVICE_ID_INTEL_ADP_S_PMC,
Subrata Banik2153ea52017-11-22 15:38:19 +0530127 0
128};
129
Subrata Banik88852062018-01-10 10:51:50 +0530130static const struct pci_driver pch_pmc __pci_driver = {
Subrata Banik2153ea52017-11-22 15:38:19 +0530131 .ops = &device_ops,
132 .vendor = PCI_VENDOR_ID_INTEL,
133 .devices = pci_device_ids,
134};