blob: cb2b266f95fe3591113af7be5d4d5469358a1e90 [file] [log] [blame]
Frank Vibrans63e62b02011-02-14 18:38:14 +00001/*
2 * This file is part of the coreboot project.
3 *
Frank Vibrans63e62b02011-02-14 18:38:14 +00004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Frank Vibrans63e62b02011-02-14 18:38:14 +000013 */
14
Kerry Shefeed3292011-08-18 18:03:44 +080015#include <console/console.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000016#include <device/pci.h>
Martin Roth3aef7b42012-12-05 15:50:32 -070017#include <device/pci_def.h>
Patrick Georgi2c2e78d2012-02-16 18:54:37 +010018#include <arch/ioapic.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000019#include "lpc.h"
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020020#include <device/pci_ops.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000021
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +020022void lpc_read_resources(struct device *dev)
Frank Vibrans63e62b02011-02-14 18:38:14 +000023{
24 struct resource *res;
25
Kerry Shefeed3292011-08-18 18:03:44 +080026 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - Start.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000027 /* Get the normal pci resources of this device */
28 pci_dev_read_resources(dev); /* We got one for APIC, or one more for TRAP */
29
Frank Vibrans63e62b02011-02-14 18:38:14 +000030 /* Add an extra subtractive resource for both memory and I/O. */
31 res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
32 res->base = 0;
33 res->size = 0x1000;
34 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
35 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
36
37 res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
38 res->base = 0xff800000;
39 res->size = 0x00800000; /* 8 MB for flash */
40 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
41 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
42
Dave Frodinac1b8752014-06-05 14:30:22 -060043 /* Add a memory resource for the SPI BAR. */
44 fixed_mem_resource(dev, 2, SPI_BASE_ADDRESS / 1024, 1, IORESOURCE_SUBTRACTIVE);
45
Patrick Georgi2c2e78d2012-02-16 18:54:37 +010046 res = new_resource(dev, 3);
47 res->base = IO_APIC_ADDR;
Frank Vibrans63e62b02011-02-14 18:38:14 +000048 res->size = 0x00001000;
49 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
50
51 compact_resources(dev);
Kerry Shefeed3292011-08-18 18:03:44 +080052 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000053}
54
55void lpc_set_resources(struct device *dev)
56{
57 struct resource *res;
58
Kerry Shefeed3292011-08-18 18:03:44 +080059 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_set_resources - Start.\n");
Martin Roth3aef7b42012-12-05 15:50:32 -070060
61 /* Special case. SPI Base Address. The SpiRomEnable should STAY set. */
Dave Frodinac1b8752014-06-05 14:30:22 -060062 res = find_resource(dev, 2);
63 pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, res->base | SPI_ROM_ENABLE);
Martin Roth3aef7b42012-12-05 15:50:32 -070064
Frank Vibrans63e62b02011-02-14 18:38:14 +000065 pci_dev_set_resources(dev);
66
Kerry Shefeed3292011-08-18 18:03:44 +080067 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_set_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000068}
69
70/**
71 * @brief Enable resources for children devices
72 *
Martin Roth3c3a50c2014-12-16 20:50:26 -070073 * @param dev the device whose children's resources are to be enabled
Frank Vibrans63e62b02011-02-14 18:38:14 +000074 *
75 */
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +020076void lpc_enable_childrens_resources(struct device *dev)
Frank Vibrans63e62b02011-02-14 18:38:14 +000077{
78 struct bus *link;
79 u32 reg, reg_x;
80 int var_num = 0;
81 u16 reg_var[3];
82
Kerry Shefeed3292011-08-18 18:03:44 +080083 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_enable_childrens_resources - Start.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000084 reg = pci_read_config32(dev, 0x44);
85 reg_x = pci_read_config32(dev, 0x48);
86
87 for (link = dev->link_list; link; link = link->next) {
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +020088 struct device *child;
Frank Vibrans63e62b02011-02-14 18:38:14 +000089 for (child = link->children; child;
90 child = child->sibling) {
91 if (child->enabled
92 && (child->path.type == DEVICE_PATH_PNP)) {
93 struct resource *res;
94 for (res = child->resource_list; res; res = res->next) {
Paul Menzel621abec2017-09-09 11:26:24 +020095 u32 base; /* don't need long long */
Frank Vibrans63e62b02011-02-14 18:38:14 +000096 if (!(res->flags & IORESOURCE_IO))
97 continue;
98 base = res->base;
Frank Vibrans63e62b02011-02-14 18:38:14 +000099/*
Paul Menzel482f8222017-09-09 11:05:21 +0200100 printk(BIOS_DEBUG, "sb800 lpc decode:%s,
101 base=0x%08x, end=0x%08x\n",
Paul Menzel621abec2017-09-09 11:26:24 +0200102 dev_path(child), base,
103 resource_end(res));
Frank Vibrans63e62b02011-02-14 18:38:14 +0000104*/
105 switch (base) {
106 case 0x60: /* KB */
107 case 0x64: /* MS */
108 reg |= (1 << 29);
109 break;
110 case 0x3f8: /* COM1 */
111 reg |= (1 << 6);
112 break;
113 case 0x2f8: /* COM2 */
114 reg |= (1 << 7);
115 break;
Martin Roth3c3a50c2014-12-16 20:50:26 -0700116 case 0x378: /* Parallel 1 */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000117 reg |= (1 << 0);
118 break;
119 case 0x3f0: /* FD0 */
120 reg |= (1 << 26);
121 break;
Martin Roth3c3a50c2014-12-16 20:50:26 -0700122 case 0x220: /* Audio 0 */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000123 reg |= (1 << 8);
124 break;
125 case 0x300: /* Midi 0 */
126 reg |= (1 << 18);
127 break;
128 case 0x400:
129 reg_x |= (1 << 16);
130 break;
131 case 0x480:
132 reg_x |= (1 << 17);
133 break;
134 case 0x500:
135 reg_x |= (1 << 18);
136 break;
137 case 0x580:
138 reg_x |= (1 << 19);
139 break;
140 case 0x4700:
141 reg_x |= (1 << 22);
142 break;
143 case 0xfd60:
144 reg_x |= (1 << 23);
145 break;
146 default:
147 if (var_num >= 3)
148 continue; /* only 3 var ; compact them ? */
149 switch (var_num) {
150 case 0:
151 reg_x |= (1 << 2);
152 break;
153 case 1:
154 reg_x |= (1 << 24);
155 break;
156 case 2:
157 reg_x |= (1 << 25);
158 break;
159 }
160 reg_var[var_num++] =
161 base & 0xffff;
162 }
163 }
164 }
165 }
166 }
167 pci_write_config32(dev, 0x44, reg);
168 pci_write_config32(dev, 0x48, reg_x);
169 /* Set WideIO for as many IOs found (fall through is on purpose) */
170 switch (var_num) {
Jacob Garbera9bf88b2019-06-25 12:46:35 -0600171 case 3:
Frank Vibrans63e62b02011-02-14 18:38:14 +0000172 pci_write_config16(dev, 0x90, reg_var[2]);
Jacob Garber4c33a3a2019-07-12 10:34:06 -0600173 /* fall through */
Jacob Garbera9bf88b2019-06-25 12:46:35 -0600174 case 2:
Frank Vibrans63e62b02011-02-14 18:38:14 +0000175 pci_write_config16(dev, 0x66, reg_var[1]);
Jacob Garber4c33a3a2019-07-12 10:34:06 -0600176 /* fall through */
Jacob Garbera9bf88b2019-06-25 12:46:35 -0600177 case 1:
Frank Vibrans63e62b02011-02-14 18:38:14 +0000178 //pci_write_config16(dev, 0x64, reg_var[0]); //cause filo can not find sata
179 break;
180 }
Kerry Shefeed3292011-08-18 18:03:44 +0800181 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_enable_childrens_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +0000182}