blob: c462d9daa0bdf0518434d13178874e14b7e5eaa7 [file] [log] [blame]
Ravi Sarawadiefa606b2017-08-04 16:26:09 -07001/*
2 * This file is part of the coreboot project.
3 *
Subrata Banik88852062018-01-10 10:51:50 +05304 * Copyright (C) 2017-2018 Intel Corp.
Ravi Sarawadiefa606b2017-08-04 16:26:09 -07005 *
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; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
Aaron Durbin64031672018-04-21 14:45:32 -060017#include <compiler.h>
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070018#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070021#include <intelblocks/acpi.h>
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070022#include <intelblocks/lpc_lib.h>
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070023#include <soc/pm.h>
24
Subrata Banik88852062018-01-10 10:51:50 +053025/* SoC overrides */
26
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070027/* Common weak definition, needs to be implemented in each soc LPC driver. */
Aaron Durbin64031672018-04-21 14:45:32 -060028__weak void lpc_soc_init(struct device *dev)
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070029{
Subrata Banik88852062018-01-10 10:51:50 +053030 /* no-op */
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070031}
32
Subrata Banik88852062018-01-10 10:51:50 +053033/* Fill up LPC IO resource structure inside SoC directory */
Aaron Durbin64031672018-04-21 14:45:32 -060034__weak void pch_lpc_soc_fill_io_resources(struct device *dev)
Subrata Banik88852062018-01-10 10:51:50 +053035{
36 /* no-op */
37}
38
39void pch_lpc_add_new_resource(struct device *dev, uint8_t offset,
40 uintptr_t base, size_t size, unsigned long flags)
41{
42 struct resource *res;
43 res = new_resource(dev, offset);
44 res->base = base;
45 res->size = size;
46 res->flags = flags;
47}
48
49static void pch_lpc_add_io_resources(device_t dev)
50{
51 /* Add the default claimed legacy IO range for the LPC device. */
52 pch_lpc_add_new_resource(dev, 0, 0, 0x1000, IORESOURCE_IO |
53 IORESOURCE_ASSIGNED | IORESOURCE_FIXED);
54
55 /* SoC IO resource overrides */
56 pch_lpc_soc_fill_io_resources(dev);
57}
58
59static void pch_lpc_read_resources(device_t dev)
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070060{
61 /* Get the PCI resources of this device. */
62 pci_dev_read_resources(dev);
63
64 /* Add IO resources to LPC. */
Subrata Banik88852062018-01-10 10:51:50 +053065 pch_lpc_add_io_resources(dev);
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070066}
67
Subrata Banik88852062018-01-10 10:51:50 +053068static void pch_lpc_set_child_resources(struct device *dev);
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070069
Subrata Banik88852062018-01-10 10:51:50 +053070static void pch_lpc_loop_resources(struct device *dev)
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070071{
72 struct resource *res;
73
74 for (res = dev->resource_list; res; res = res->next) {
75 if (res->flags & IORESOURCE_IO)
76 lpc_open_pmio_window(res->base, res->size);
77
78 if (res->flags & IORESOURCE_MEM) {
79 /* Check if this is already decoded. */
80 if (lpc_fits_fixed_mmio_window(res->base, res->size))
81 continue;
82
83 lpc_open_mmio_window(res->base, res->size);
84 }
85 }
Subrata Banik88852062018-01-10 10:51:50 +053086 pch_lpc_set_child_resources(dev);
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070087}
88
89/*
90 * Loop through all the child devices' resources, and open up windows to the
91 * LPC bus, as appropriate.
92 */
Subrata Banik88852062018-01-10 10:51:50 +053093static void pch_lpc_set_child_resources(struct device *dev)
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070094{
95 struct bus *link;
96 struct device *child;
97
98 for (link = dev->link_list; link; link = link->next) {
99 for (child = link->children; child; child = child->sibling)
Subrata Banik88852062018-01-10 10:51:50 +0530100 pch_lpc_loop_resources(child);
Ravi Sarawadiefa606b2017-08-04 16:26:09 -0700101 }
102}
103
Subrata Banik88852062018-01-10 10:51:50 +0530104static void pch_lpc_set_resources(device_t dev)
Ravi Sarawadiefa606b2017-08-04 16:26:09 -0700105{
106 pci_dev_set_resources(dev);
107
108 /* Now open up windows to devices which have declared resources. */
Subrata Banik88852062018-01-10 10:51:50 +0530109 pch_lpc_set_child_resources(dev);
Ravi Sarawadiefa606b2017-08-04 16:26:09 -0700110}
111
112static struct device_operations device_ops = {
Subrata Banik88852062018-01-10 10:51:50 +0530113 .read_resources = pch_lpc_read_resources,
114 .set_resources = pch_lpc_set_resources,
Subrata Banik6bbc91a2017-12-07 14:55:51 +0530115 .enable_resources = pci_dev_enable_resources,
116 .write_acpi_tables = southbridge_write_acpi_tables,
117 .acpi_inject_dsdt_generator = southbridge_inject_dsdt,
Subrata Banik88852062018-01-10 10:51:50 +0530118 .init = lpc_soc_init,
Subrata Banik6bbc91a2017-12-07 14:55:51 +0530119 .scan_bus = scan_lpc_bus,
120 .ops_pci = &pci_dev_ops_pci,
Ravi Sarawadiefa606b2017-08-04 16:26:09 -0700121};
122
123static const unsigned short pci_device_ids[] = {
124 PCI_DEVICE_ID_INTEL_SPT_LP_SAMPLE,
125 PCI_DEVICE_ID_INTEL_SPT_LP_U_BASE,
126 PCI_DEVICE_ID_INTEL_SPT_LP_U_PREMIUM,
127 PCI_DEVICE_ID_INTEL_SPT_LP_Y_PREMIUM,
V Sowmya7c150472018-01-23 14:44:45 +0530128 PCI_DEVICE_ID_INTEL_SPT_H_C236,
129 PCI_DEVICE_ID_INTEL_SPT_H_PREMIUM,
130 PCI_DEVICE_ID_INTEL_SPT_H_QM170,
V Sowmyaacc2a482018-01-23 15:27:23 +0530131 PCI_DEVICE_ID_INTEL_KBP_H_Q270,
Gaggery Tsaie415a4c2018-03-21 22:36:18 +0800132 PCI_DEVICE_ID_INTEL_KBP_H_H270,
133 PCI_DEVICE_ID_INTEL_KBP_H_Z270,
134 PCI_DEVICE_ID_INTEL_KBP_H_Q250,
135 PCI_DEVICE_ID_INTEL_KBP_H_B250,
Ravi Sarawadiefa606b2017-08-04 16:26:09 -0700136 PCI_DEVICE_ID_INTEL_SPT_LP_Y_PREMIUM_HDCP22,
137 PCI_DEVICE_ID_INTEL_SPT_LP_U_PREMIUM_HDCP22,
Gaggery Tsaie2592be2017-09-20 22:46:39 +0800138 PCI_DEVICE_ID_INTEL_SPT_LP_U_BASE_HDCP22,
Ravi Sarawadiefa606b2017-08-04 16:26:09 -0700139 PCI_DEVICE_ID_INTEL_KBP_LP_SUPER_SKU,
140 PCI_DEVICE_ID_INTEL_KBP_LP_U_PREMIUM,
141 PCI_DEVICE_ID_INTEL_KBP_LP_Y_PREMIUM,
142 PCI_DEVICE_ID_INTEL_APL_LPC,
143 PCI_DEVICE_ID_INTEL_GLK_LPC,
Bora Guvendik94aed8d2017-11-03 12:40:25 -0700144 PCI_DEVICE_ID_INTEL_GLK_ESPI,
Lijian Zhaof7bcc182017-09-25 23:58:39 -0700145 PCI_DEVICE_ID_INTEL_CNL_BASE_U_LPC,
146 PCI_DEVICE_ID_INTEL_CNL_U_PREMIUM_LPC,
Bora Guvendika0e0b052017-09-15 16:52:05 -0700147 PCI_DEVICE_ID_INTEL_CNL_Y_PREMIUM_LPC,
Ravi Sarawadiefa606b2017-08-04 16:26:09 -0700148 0
149};
150
Subrata Banik88852062018-01-10 10:51:50 +0530151static const struct pci_driver pch_lpc __pci_driver = {
Ravi Sarawadiefa606b2017-08-04 16:26:09 -0700152 .ops = &device_ops,
153 .vendor = PCI_VENDOR_ID_INTEL,
154 .devices = pci_device_ids,
155};