blob: 55329550ab1ccefd8243344ff8ff7fae91c8bb01 [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
17#include <device/device.h>
18#include <device/pci.h>
19#include <device/pci_ids.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070020#include <intelblocks/acpi.h>
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070021#include <intelblocks/lpc_lib.h>
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070022#include <soc/pm.h>
23
Subrata Banik88852062018-01-10 10:51:50 +053024/* SoC overrides */
25
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070026/* Common weak definition, needs to be implemented in each soc LPC driver. */
Subrata Banik88852062018-01-10 10:51:50 +053027__attribute__((weak)) void lpc_soc_init(struct device *dev)
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070028{
Subrata Banik88852062018-01-10 10:51:50 +053029 /* no-op */
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070030}
31
Subrata Banik88852062018-01-10 10:51:50 +053032/* Fill up LPC IO resource structure inside SoC directory */
33__attribute__((weak)) void pch_lpc_soc_fill_io_resources(struct device *dev)
34{
35 /* no-op */
36}
37
38void pch_lpc_add_new_resource(struct device *dev, uint8_t offset,
39 uintptr_t base, size_t size, unsigned long flags)
40{
41 struct resource *res;
42 res = new_resource(dev, offset);
43 res->base = base;
44 res->size = size;
45 res->flags = flags;
46}
47
48static void pch_lpc_add_io_resources(device_t dev)
49{
50 /* Add the default claimed legacy IO range for the LPC device. */
51 pch_lpc_add_new_resource(dev, 0, 0, 0x1000, IORESOURCE_IO |
52 IORESOURCE_ASSIGNED | IORESOURCE_FIXED);
53
54 /* SoC IO resource overrides */
55 pch_lpc_soc_fill_io_resources(dev);
56}
57
58static void pch_lpc_read_resources(device_t dev)
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070059{
60 /* Get the PCI resources of this device. */
61 pci_dev_read_resources(dev);
62
63 /* Add IO resources to LPC. */
Subrata Banik88852062018-01-10 10:51:50 +053064 pch_lpc_add_io_resources(dev);
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070065}
66
Subrata Banik88852062018-01-10 10:51:50 +053067static void pch_lpc_set_child_resources(struct device *dev);
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070068
Subrata Banik88852062018-01-10 10:51:50 +053069static void pch_lpc_loop_resources(struct device *dev)
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070070{
71 struct resource *res;
72
73 for (res = dev->resource_list; res; res = res->next) {
74 if (res->flags & IORESOURCE_IO)
75 lpc_open_pmio_window(res->base, res->size);
76
77 if (res->flags & IORESOURCE_MEM) {
78 /* Check if this is already decoded. */
79 if (lpc_fits_fixed_mmio_window(res->base, res->size))
80 continue;
81
82 lpc_open_mmio_window(res->base, res->size);
83 }
84 }
Subrata Banik88852062018-01-10 10:51:50 +053085 pch_lpc_set_child_resources(dev);
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070086}
87
88/*
89 * Loop through all the child devices' resources, and open up windows to the
90 * LPC bus, as appropriate.
91 */
Subrata Banik88852062018-01-10 10:51:50 +053092static void pch_lpc_set_child_resources(struct device *dev)
Ravi Sarawadiefa606b2017-08-04 16:26:09 -070093{
94 struct bus *link;
95 struct device *child;
96
97 for (link = dev->link_list; link; link = link->next) {
98 for (child = link->children; child; child = child->sibling)
Subrata Banik88852062018-01-10 10:51:50 +053099 pch_lpc_loop_resources(child);
Ravi Sarawadiefa606b2017-08-04 16:26:09 -0700100 }
101}
102
Subrata Banik88852062018-01-10 10:51:50 +0530103static void pch_lpc_set_resources(device_t dev)
Ravi Sarawadiefa606b2017-08-04 16:26:09 -0700104{
105 pci_dev_set_resources(dev);
106
107 /* Now open up windows to devices which have declared resources. */
Subrata Banik88852062018-01-10 10:51:50 +0530108 pch_lpc_set_child_resources(dev);
Ravi Sarawadiefa606b2017-08-04 16:26:09 -0700109}
110
111static struct device_operations device_ops = {
Subrata Banik88852062018-01-10 10:51:50 +0530112 .read_resources = pch_lpc_read_resources,
113 .set_resources = pch_lpc_set_resources,
Subrata Banik6bbc91a2017-12-07 14:55:51 +0530114 .enable_resources = pci_dev_enable_resources,
115 .write_acpi_tables = southbridge_write_acpi_tables,
116 .acpi_inject_dsdt_generator = southbridge_inject_dsdt,
Subrata Banik88852062018-01-10 10:51:50 +0530117 .init = lpc_soc_init,
Subrata Banik6bbc91a2017-12-07 14:55:51 +0530118 .scan_bus = scan_lpc_bus,
119 .ops_pci = &pci_dev_ops_pci,
Ravi Sarawadiefa606b2017-08-04 16:26:09 -0700120};
121
122static const unsigned short pci_device_ids[] = {
123 PCI_DEVICE_ID_INTEL_SPT_LP_SAMPLE,
124 PCI_DEVICE_ID_INTEL_SPT_LP_U_BASE,
125 PCI_DEVICE_ID_INTEL_SPT_LP_U_PREMIUM,
126 PCI_DEVICE_ID_INTEL_SPT_LP_Y_PREMIUM,
127 PCI_DEVICE_ID_INTEL_KBP_H_C236,
128 PCI_DEVICE_ID_INTEL_KBP_H_PREMIUM,
129 PCI_DEVICE_ID_INTEL_KBP_H_QM170,
130 PCI_DEVICE_ID_INTEL_SPT_LP_Y_PREMIUM_HDCP22,
131 PCI_DEVICE_ID_INTEL_SPT_LP_U_PREMIUM_HDCP22,
Gaggery Tsaie2592be2017-09-20 22:46:39 +0800132 PCI_DEVICE_ID_INTEL_SPT_LP_U_BASE_HDCP22,
Ravi Sarawadiefa606b2017-08-04 16:26:09 -0700133 PCI_DEVICE_ID_INTEL_KBP_LP_SUPER_SKU,
134 PCI_DEVICE_ID_INTEL_KBP_LP_U_PREMIUM,
135 PCI_DEVICE_ID_INTEL_KBP_LP_Y_PREMIUM,
136 PCI_DEVICE_ID_INTEL_APL_LPC,
137 PCI_DEVICE_ID_INTEL_GLK_LPC,
Bora Guvendik94aed8d2017-11-03 12:40:25 -0700138 PCI_DEVICE_ID_INTEL_GLK_ESPI,
Lijian Zhaof7bcc182017-09-25 23:58:39 -0700139 PCI_DEVICE_ID_INTEL_CNL_BASE_U_LPC,
140 PCI_DEVICE_ID_INTEL_CNL_U_PREMIUM_LPC,
Bora Guvendika0e0b052017-09-15 16:52:05 -0700141 PCI_DEVICE_ID_INTEL_CNL_Y_PREMIUM_LPC,
Ravi Sarawadiefa606b2017-08-04 16:26:09 -0700142 0
143};
144
Subrata Banik88852062018-01-10 10:51:50 +0530145static const struct pci_driver pch_lpc __pci_driver = {
Ravi Sarawadiefa606b2017-08-04 16:26:09 -0700146 .ops = &device_ops,
147 .vendor = PCI_VENDOR_ID_INTEL,
148 .devices = pci_device_ids,
149};