blob: 3f0ff7fea338f0a54ae14e7b034975a4093ff7d7 [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Frank Vibrans63e62b02011-02-14 18:38:14 +00003
Kerry Shefeed3292011-08-18 18:03:44 +08004#include <console/console.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +00005#include <device/pci.h>
Martin Roth3aef7b42012-12-05 15:50:32 -07006#include <device/pci_def.h>
Patrick Georgi2c2e78d2012-02-16 18:54:37 +01007#include <arch/ioapic.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +00008#include "lpc.h"
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02009#include <device/pci_ops.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000010
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +020011void lpc_read_resources(struct device *dev)
Frank Vibrans63e62b02011-02-14 18:38:14 +000012{
13 struct resource *res;
14
Kerry Shefeed3292011-08-18 18:03:44 +080015 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - Start.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000016 /* Get the normal pci resources of this device */
17 pci_dev_read_resources(dev); /* We got one for APIC, or one more for TRAP */
18
Frank Vibrans63e62b02011-02-14 18:38:14 +000019 /* Add an extra subtractive resource for both memory and I/O. */
20 res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
21 res->base = 0;
22 res->size = 0x1000;
23 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
24 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
25
26 res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
27 res->base = 0xff800000;
28 res->size = 0x00800000; /* 8 MB for flash */
29 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
30 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
31
Dave Frodinac1b8752014-06-05 14:30:22 -060032 /* Add a memory resource for the SPI BAR. */
33 fixed_mem_resource(dev, 2, SPI_BASE_ADDRESS / 1024, 1, IORESOURCE_SUBTRACTIVE);
34
Patrick Georgi2c2e78d2012-02-16 18:54:37 +010035 res = new_resource(dev, 3);
36 res->base = IO_APIC_ADDR;
Frank Vibrans63e62b02011-02-14 18:38:14 +000037 res->size = 0x00001000;
38 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
39
40 compact_resources(dev);
Kerry Shefeed3292011-08-18 18:03:44 +080041 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000042}
43
44void lpc_set_resources(struct device *dev)
45{
46 struct resource *res;
47
Kerry Shefeed3292011-08-18 18:03:44 +080048 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_set_resources - Start.\n");
Martin Roth3aef7b42012-12-05 15:50:32 -070049
50 /* Special case. SPI Base Address. The SpiRomEnable should STAY set. */
Dave Frodinac1b8752014-06-05 14:30:22 -060051 res = find_resource(dev, 2);
52 pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, res->base | SPI_ROM_ENABLE);
Martin Roth3aef7b42012-12-05 15:50:32 -070053
Frank Vibrans63e62b02011-02-14 18:38:14 +000054 pci_dev_set_resources(dev);
55
Kerry Shefeed3292011-08-18 18:03:44 +080056 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_set_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000057}
58
59/**
60 * @brief Enable resources for children devices
61 *
Martin Roth3c3a50c2014-12-16 20:50:26 -070062 * @param dev the device whose children's resources are to be enabled
Frank Vibrans63e62b02011-02-14 18:38:14 +000063 *
64 */
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +020065void lpc_enable_childrens_resources(struct device *dev)
Frank Vibrans63e62b02011-02-14 18:38:14 +000066{
67 struct bus *link;
68 u32 reg, reg_x;
69 int var_num = 0;
70 u16 reg_var[3];
71
Kerry Shefeed3292011-08-18 18:03:44 +080072 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_enable_childrens_resources - Start.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000073 reg = pci_read_config32(dev, 0x44);
74 reg_x = pci_read_config32(dev, 0x48);
75
76 for (link = dev->link_list; link; link = link->next) {
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +020077 struct device *child;
Frank Vibrans63e62b02011-02-14 18:38:14 +000078 for (child = link->children; child;
79 child = child->sibling) {
80 if (child->enabled
81 && (child->path.type == DEVICE_PATH_PNP)) {
82 struct resource *res;
83 for (res = child->resource_list; res; res = res->next) {
Paul Menzel621abec2017-09-09 11:26:24 +020084 u32 base; /* don't need long long */
Frank Vibrans63e62b02011-02-14 18:38:14 +000085 if (!(res->flags & IORESOURCE_IO))
86 continue;
87 base = res->base;
Frank Vibrans63e62b02011-02-14 18:38:14 +000088/*
Paul Menzel482f8222017-09-09 11:05:21 +020089 printk(BIOS_DEBUG, "sb800 lpc decode:%s,
90 base=0x%08x, end=0x%08x\n",
Paul Menzel621abec2017-09-09 11:26:24 +020091 dev_path(child), base,
92 resource_end(res));
Frank Vibrans63e62b02011-02-14 18:38:14 +000093*/
94 switch (base) {
95 case 0x60: /* KB */
96 case 0x64: /* MS */
97 reg |= (1 << 29);
98 break;
99 case 0x3f8: /* COM1 */
100 reg |= (1 << 6);
101 break;
102 case 0x2f8: /* COM2 */
103 reg |= (1 << 7);
104 break;
Martin Roth3c3a50c2014-12-16 20:50:26 -0700105 case 0x378: /* Parallel 1 */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000106 reg |= (1 << 0);
107 break;
108 case 0x3f0: /* FD0 */
109 reg |= (1 << 26);
110 break;
Martin Roth3c3a50c2014-12-16 20:50:26 -0700111 case 0x220: /* Audio 0 */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000112 reg |= (1 << 8);
113 break;
114 case 0x300: /* Midi 0 */
115 reg |= (1 << 18);
116 break;
117 case 0x400:
118 reg_x |= (1 << 16);
119 break;
120 case 0x480:
121 reg_x |= (1 << 17);
122 break;
123 case 0x500:
124 reg_x |= (1 << 18);
125 break;
126 case 0x580:
127 reg_x |= (1 << 19);
128 break;
129 case 0x4700:
130 reg_x |= (1 << 22);
131 break;
132 case 0xfd60:
133 reg_x |= (1 << 23);
134 break;
135 default:
136 if (var_num >= 3)
137 continue; /* only 3 var ; compact them ? */
138 switch (var_num) {
139 case 0:
140 reg_x |= (1 << 2);
141 break;
142 case 1:
143 reg_x |= (1 << 24);
144 break;
145 case 2:
146 reg_x |= (1 << 25);
147 break;
148 }
149 reg_var[var_num++] =
150 base & 0xffff;
151 }
152 }
153 }
154 }
155 }
156 pci_write_config32(dev, 0x44, reg);
157 pci_write_config32(dev, 0x48, reg_x);
158 /* Set WideIO for as many IOs found (fall through is on purpose) */
159 switch (var_num) {
Jacob Garbera9bf88b2019-06-25 12:46:35 -0600160 case 3:
Frank Vibrans63e62b02011-02-14 18:38:14 +0000161 pci_write_config16(dev, 0x90, reg_var[2]);
Jacob Garber4c33a3a2019-07-12 10:34:06 -0600162 /* fall through */
Jacob Garbera9bf88b2019-06-25 12:46:35 -0600163 case 2:
Frank Vibrans63e62b02011-02-14 18:38:14 +0000164 pci_write_config16(dev, 0x66, reg_var[1]);
Jacob Garber4c33a3a2019-07-12 10:34:06 -0600165 /* fall through */
Jacob Garbera9bf88b2019-06-25 12:46:35 -0600166 case 1:
Frank Vibrans63e62b02011-02-14 18:38:14 +0000167 //pci_write_config16(dev, 0x64, reg_var[0]); //cause filo can not find sata
168 break;
169 }
Kerry Shefeed3292011-08-18 18:03:44 +0800170 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_enable_childrens_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +0000171}